Skip to content

Instantly share code, notes, and snippets.

View hohlick's full-sized avatar

Maxim Zelensky hohlick

View GitHub Profile
Sparkline Line =
// Static line color
VAR LineColor = "#01B8AA"
// "Date" field used in this example along the X axis
VAR XMinDate = MIN('Table'[Date])
VAR XMaxDate = MAX('Table'[Date])
// Obtain overall min and overall max measure values when evaluated for each date
@hohlick
hohlick / Table_ConvertColumnTypes.pq
Created May 15, 2018 14:15
Autodetect and Convert Column Types in Power Query (based on first 200 rows)
// Author: Colin Banfield (https://social.technet.microsoft.com/profile/colin%20banfield/?ws=usercard-mini)
// Source: https://social.technet.microsoft.com/Forums/en-US/ee911661-6cb1-48ac-ae46-d70979b35cb7/homogeneous-list-types-in-m?forum=powerquery
//
(table as table, optional culture as nullable text) as table =>
let
ValidTypes = {type any, type number, type date, type datetime, type datetimezone,
type time, type duration, type logical, type text, type binary,
Int64.Type, Percentage.Type, Currency.Type
},
@hohlick
hohlick / Table.MassReplaceValuesJ.pq
Created February 20, 2018 16:10
Power Query / Power BI / M function for mass values replacement in a table column (Join version)
(
SourceTable as table, // table to make replacements in
ToReplace as text, // name of the column for replacements
ReplacementTable as table // table with columns named "What" and "With" (with "what to replace" and "replace with" values respectively)
) as table =>
let
JoinColumnName = Text.NewGuid(),
Correct = Table.NestedJoin(SourceTable, {ToReplace}, ReplacementTable, {"What"}, JoinColumnName, JoinKind.LeftAnti),
Part1 = Table.RemoveColumns(Correct, JoinColumnName),
@hohlick
hohlick / Table.MassReplaceValues.pq
Created February 20, 2018 16:06
Power Query / Power BI / M function for mass values replacement in a table column (List version)
// fnMassReplace
(
Source as table, // table to make replacements in
ToReplace as text, // name of the column for replacements
ReplaceWhat as list, // list (or column reference) with "what to replace" values
ReplaceWith as list // list (or column reference) with "replace with" values
) as table =>
let
CurrentColumns = List.Buffer(Table.ColumnNames(Source)),
@hohlick
hohlick / UnZIP.m
Created August 10, 2017 15:15 — forked from Hugoberry/UnZIP.m
UnZip in Power Query M
(ZIPFile) =>
let
Header = BinaryFormat.Record([ Signature = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32,ByteOrder.LittleEndian),
Version = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16,ByteOrder.LittleEndian),
Flags = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16,ByteOrder.LittleEndian),
Compression = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16,ByteOrder.LittleEndian),
ModTime = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16,ByteOrder.LittleEndian),
ModDate = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16,ByteOrder.LittleEndian),
CRC32 = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32,ByteOrder.LittleEndian),
CompressedSize = BinaryFormat.ByteOrde
@hohlick
hohlick / JSON2table.m
Created February 28, 2017 13:40 — forked from Hugoberry/JSON2table.m
JSON to Table in Power Query M
(json) =>
let
//List the expandable columns
expandableColumns = (_) => List.Accumulate(
Table.ColumnNames(_),
{},
(s,c)=>s&(if Type.Is(Value.Type(Record.Field(_{0},c)), type record)
or Type.Is(Value.Type(Record.Field(_{0},c)), type list)
then {c}
else {})