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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Shalva
New Member

Getting Data bewteen range of dates

Hello

I have a table of workers with dates

NameStart Date in the companyEnd Date in the company
A15/03/2031/03/20
B01/03/2031/04/20
C10/03/2010/05/20

And so on...

I want to alculate and show the amount of wages that have been paid each month

 

NameMarchAprilMay
A0.500
B110
C0.610.3

 

I want to find the best and efficent way to do it because I have a lot of workers and can't make 12 rows for each month for each individual.

I tried to make a measure for each month but it didn't work

 

MeasureMarch=

var StartMonth = Max( Table[Start Date], Date(2020,03,01))

var EndMonth = Min( Date(2020,03,31), Table[End Date])

var Wage=Calculate((NextMonth-ThisMonth)/30)

FlagAnd( Month(StartMonth)=3, Month(EndMonth=3)), 

return If( Flag, Wage, 0)

 

Any thoughts?

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

@Shalva , both DAX and Power Query do the trick.

 

DAX solution

Screenshot 2021-02-19 021925.png

 

PQ solution,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI01Tcw1jcyADKNDaHMWJ1oJSeggIEhQs5A38AEJucM0mcAlwMxTcFysQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Start Date in the company" = _t, #"End Date in the company" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Start Date in the company", type date}, {"End Date in the company", type date}}, "Fr"),
    #"Added Custom" = Table.AddColumn(
        #"Changed Type",
        "Custom",
        each List.Accumulate(
            List.Dates([Start Date in the company], Duration.Days([End Date in the company]-[Start Date in the company])+1,#duration(1,0,0,0)),
            [],
            (s,c) => let yyyyMM = Date.ToText(c, "yyyyMM"), value = Record.FieldOrDefault(s, yyyyMM, "NA") in if value = "NA" then Record.AddField(s, yyyyMM, 1) else s & Record.AddField([], yyyyMM, value+1)
        )
    ),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Start Date in the company", "End Date in the company"}),
    Custom1 = Table.TransformColumns(
        #"Removed Columns",
        {{"Custom",
            each List.Accumulate(
                Record.FieldNames(_),
                [],
                (s,c) => Record.AddField(s, c, Number.Round(Record.Field(_,c)/Date.DaysInMonth(Date.From(c&"01")),2))
            )
        }}
    ),
    #"Expanded Custom" = Table.ExpandRecordColumn(Custom1, "Custom", {"202003", "202004", "202005"}, {"202003", "202004", "202005"})
in
    #"Expanded Custom"

Screenshot 2021-02-19 022312.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

1 REPLY 1
CNENFRNL
Community Champion
Community Champion

@Shalva , both DAX and Power Query do the trick.

 

DAX solution

Screenshot 2021-02-19 021925.png

 

PQ solution,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI01Tcw1jcyADKNDaHMWJ1oJSeggIEhQs5A38AEJucM0mcAlwMxTcFysQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Start Date in the company" = _t, #"End Date in the company" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Start Date in the company", type date}, {"End Date in the company", type date}}, "Fr"),
    #"Added Custom" = Table.AddColumn(
        #"Changed Type",
        "Custom",
        each List.Accumulate(
            List.Dates([Start Date in the company], Duration.Days([End Date in the company]-[Start Date in the company])+1,#duration(1,0,0,0)),
            [],
            (s,c) => let yyyyMM = Date.ToText(c, "yyyyMM"), value = Record.FieldOrDefault(s, yyyyMM, "NA") in if value = "NA" then Record.AddField(s, yyyyMM, 1) else s & Record.AddField([], yyyyMM, value+1)
        )
    ),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Start Date in the company", "End Date in the company"}),
    Custom1 = Table.TransformColumns(
        #"Removed Columns",
        {{"Custom",
            each List.Accumulate(
                Record.FieldNames(_),
                [],
                (s,c) => Record.AddField(s, c, Number.Round(Record.Field(_,c)/Date.DaysInMonth(Date.From(c&"01")),2))
            )
        }}
    ),
    #"Expanded Custom" = Table.ExpandRecordColumn(Custom1, "Custom", {"202003", "202004", "202005"}, {"202003", "202004", "202005"})
in
    #"Expanded Custom"

Screenshot 2021-02-19 022312.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (27)