Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
annie_liu
Helper I
Helper I

Conversing DAX to custom column Query Setting

Hello - calculate how many holidays employee should taken since offboarding date 

 

I twas trying figure out how to do this in the power query.

Holiday_days = var _start_date = IF( [OnBoardText] > MIN('Calendar'[Date]) ,[OnBoardText], MIN('Calendar'[Date]))

var _t= FILTER('Calendar','Calendar'[Date] >= _start_date && 'Calendar'[Date] <= [OffBoardText])

return

SUMX(_t,[is_holiday])

 

Calendar [Date] is another table.. while the onboard is within the same table

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @annie_liu ,

 

My approach was a bit complicated, but I made it. You can refer to the following M code. You can also download my attachment to see details.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDLUtdA1MoawjXQNdY0MlWJ1opWMkERgTCDHDCwJUg4TNAXriAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, OnBoardText = _t, OffBoardText = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"OnBoardText", type date}, {"OffBoardText", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.Min(#"Table (2)","Date")),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Date"}, {"Custom.Date"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom.Date", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "MinDate", each if [OnBoardText] = null then [Custom.Date] else if [Custom.Date] < [OnBoardText] then [OnBoardText] else [Custom.Date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom.Date"}),
    #"Added Custom2" = Table.AddColumn(#"Removed Columns", "Custom", each #"Table"),
    #"Expanded Custom1" = Table.ExpandTableColumn(#"Added Custom2", "Custom", {"Date", "Holiday Count"}, {"Date", "Holiday Count"}),
    #"Added Custom3" = Table.AddColumn(#"Expanded Custom1", "Custom", each if [MinDate]<=[Date] and [OffBoardText]>=[Date] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom3", each ([Custom] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}),
    #"Filtered Rows1" = Table.SelectRows(#"Removed Columns1", each ([Holiday Count] = 1)),
    #"Grouped Rows" = Table.Group(#"Filtered Rows1", {"Id"}, {{"All Rows", each _, type table [Id=nullable number, OnBoardText=nullable date, OffBoardText=nullable date, MinDate=date, Date=date, Holiday Count=number]}, {"Holiday Count", each Table.RowCount(_), Int64.Type}}),
    #"Expanded All Rows" = Table.ExpandTableColumn(#"Grouped Rows", "All Rows", {"Id", "OnBoardText", "OffBoardText"}, {"Id.1", "OnBoardText", "OffBoardText"})
in
    #"Expanded All Rows"

 

vstephenmsft_0-1667985689389.png

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
v-stephen-msft
Community Support
Community Support

Hi @annie_liu ,

 

My approach was a bit complicated, but I made it. You can refer to the following M code. You can also download my attachment to see details.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDLUtdA1MoawjXQNdY0MlWJ1opWMkERgTCDHDCwJUg4TNAXriAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, OnBoardText = _t, OffBoardText = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"OnBoardText", type date}, {"OffBoardText", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.Min(#"Table (2)","Date")),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Date"}, {"Custom.Date"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom.Date", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "MinDate", each if [OnBoardText] = null then [Custom.Date] else if [Custom.Date] < [OnBoardText] then [OnBoardText] else [Custom.Date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom.Date"}),
    #"Added Custom2" = Table.AddColumn(#"Removed Columns", "Custom", each #"Table"),
    #"Expanded Custom1" = Table.ExpandTableColumn(#"Added Custom2", "Custom", {"Date", "Holiday Count"}, {"Date", "Holiday Count"}),
    #"Added Custom3" = Table.AddColumn(#"Expanded Custom1", "Custom", each if [MinDate]<=[Date] and [OffBoardText]>=[Date] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom3", each ([Custom] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}),
    #"Filtered Rows1" = Table.SelectRows(#"Removed Columns1", each ([Holiday Count] = 1)),
    #"Grouped Rows" = Table.Group(#"Filtered Rows1", {"Id"}, {{"All Rows", each _, type table [Id=nullable number, OnBoardText=nullable date, OffBoardText=nullable date, MinDate=date, Date=date, Holiday Count=number]}, {"Holiday Count", each Table.RowCount(_), Int64.Type}}),
    #"Expanded All Rows" = Table.ExpandTableColumn(#"Grouped Rows", "All Rows", {"Id", "OnBoardText", "OffBoardText"}, {"Id.1", "OnBoardText", "OffBoardText"})
in
    #"Expanded All Rows"

 

vstephenmsft_0-1667985689389.png

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors