Skip to content

Instantly share code, notes, and snippets.

View PBIQueryous's full-sized avatar
💭
Still queryous 🤓

Imran Haq PBIQueryous

💭
Still queryous 🤓
View GitHub Profile
@PBIQueryous
PBIQueryous / M-code Function Template.md
Created April 24, 2022 13:12
M-code template for creating functions
let
    // --- Function segment ---
    // Author: Imran Haq (PBI Queryous)
    output = //fnFunctionName
        (input as list) as table =>
    let
        step1 = "PowerQueryFunctionsHere"
    in
        step1
@PBIQueryous
PBIQueryous / pqDocumentationAllowedValues.md
Last active April 25, 2022 09:54
Trying to figure out AllowedValues parameter metadata
let
  Source = 
    let
      func =  // fnPowerTrim              
      
        let
          input = (text as text, optional char_to_trim as text) =>
            let
              char = if char_to_trim = null then " " else char_to_trim, 
@PBIQueryous
PBIQueryous / DAX_LatestMTD.md
Created April 26, 2022 13:20
Latest MTD calculation
Measure | CFYTD =
// current fiscal year to date of [BaseMeasure]
VAR _ytd =
    CALCULATE ( MAX ( _Dates[LatestMTD] ), REMOVEFILTERS () )
VAR _result =
    CALCULATE (
        [BaseMeasure],
        KEEPFILTERS ( _Dates[Date] <= _ytd ) 
 // , Dates[IsCFY] = TRUE

Function: Convert Fiscal Period to Month Number

fnFiscalPeriodToMonth

let
  fn =  // fnFiscalPeriodToMonth
/* ------------------------------ 
  Author: Imran Haq - PBI QUERYOUS
  GitHub: https://github.com/PBIQueryous/M-Code/
  Description: Takes Fiscal Period and Converts to Month Number

Function to get Fiscal Period from Month number

fnGetFiscalPeriodFromMonth

let
  fn =  // fnFiscalPeriodToMonth
/* ------------------------------ 
  Author: Imran Haq - PBI QUERYOUS
  GitHub: https://github.com/PBIQueryous/M-Code/
  Description: Takes Fiscal Period and Converts to Month Number
@PBIQueryous
PBIQueryous / greyBlankPBITheme.json
Created June 27, 2022 09:58
greyBlankPBITheme
{
"name": "Grey Theme",
"dataColors": [
"#3053FF",
"#A7B6FF",
"#70ACD6",
"#70C8BB",
"#AFC280",
"#BB7C7C",
"#FBD188",
@PBIQueryous
PBIQueryous / fnGetCalendarMonth.md
Created August 22, 2022 09:33
Function to retrieve Calendar Month for a list of Fiscal Periods ordered by Fiscal Start Month

fnGetCalendarMonth

PowerQuery function

Function to retrieve Calendar Month for a list of Fiscal Periods ordered by Fiscal Start Month
let
  function1 =  // fnGetCalendarMonth                 
/* ------------------------------ 
  Author: Imran Haq - PBI QUERYOUS
  Description: Get Calendar Month Number from Fiscal Period Number
@PBIQueryous
PBIQueryous / fnReplaceBlanksRemoveNulls.md
Created September 13, 2022 17:34
Replaces blanks with nulls, then removes null rows and columns
let
  customFunction =  // fnReplaceBlanksRemoveNulls                 
/* ------------------------------ 
  Author: Imran Haq - PBI QUERYOUS
  Description: fnReplaceBlanksRemoveNulls
 ---------------------------------*/

// 1.0: invoke function & define parameter inputs
    let
@PBIQueryous
PBIQueryous / 25DaysDAX_Day1.dax
Last active October 4, 2022 08:15
25 Days of DAX Fridays - Day1
Day1 Answer =
var _result =
MAXX(
TOPN( 1, // return top 1
VALUES( tournaments_standings[team_name] ), // iterate over tournaments_standings table
CALCULATE(
COUNTROWS( tournaments_standings ), // count all rows in table
tournaments_standings[position] = 1 // where position is first place
Host Wins =
FILTER(
SELECTCOLUMNS(
tournaments,
"Team", [winner],
"Host Win", [host_won]
),
[Host Win] = 1
)