Forum Discussion

ksha_001's avatar
ksha_001
Regular Visitor
2 years ago
Solved

Delta between current month and last month (Monthly Data)

I have a monthly data table with details of multiple clients and their entity IDs. I am trying to calculate the difference between the current month's entity count and the previous month's entity count. I attempted to use some formulas but did not get the desired output. I created a calendar for the dates and then calculated the current and previous month's data. Can someone please assist me with this?

 

Current Month = CALCULATE(COUNT('Query1'[AH_Internal_Claim_ID]), FILTER(ALL('DT'),'DT'[Month Rank]=max('DT'[Month Rank])))
Last Month = CALCULATE(COUNT('Query1'[AH_Internal_Claim_ID]), FILTER(ALL('DT'),'DT'[Month Rank]=max('DT'[Month Rank])-1))

Please see the below example for reference:

 

Input data

transactionMonthscompany
920230331XYZ
1020230331XYZ
1120230331XYZ
1220230331XYZ
1320230331XYZ
1420230331XYZ
120230331ABC
220230331ABC
320230331ABC
420230331ABC
520230331ABC
11320230331TMT
11420230331TMT
11520230331TMT
11620230331TMT
1520230430XYZ
1620230430XYZ
1720230430XYZ
1820230430XYZ
1920230430XYZ
2020230430XYZ
620230430ABC
720230430ABC
820230430ABC
920230430ABC
1020230430ABC
11720230430TMT
11820230430TMT
11920230430TMT
12020230430TMT
2120230531XYZ
2220230531XYZ
2320230531XYZ
2420230531XYZ
2520230531XYZ
2620230531XYZ
1120230531ABC
1220230531ABC
1320230531ABC
1420230531ABC
1520230531ABC
1620230531ABC
1720230531ABC
1820230531ABC
1920230531ABC
12120230531TMT
12220230531TMT
12320230531TMT
12420230531TMT
12520230531TMT
12620230531TMT
12720230531TMT
12820230531TMT
12920230531TMT
13020230531TMT

 

Output: 

Company202303312023043020230531Current-Previous Month
ABC5594
TMT44106
XYZ6660
  • ksha_001 Should be something like this:

    Measure = 
        VAR __Current = MAX('Table'[Months])
        VAR __PrevMonth = MAXX(FILTER('Table', [Months] <> __Current), [Months])
        VAR __CurrentTable = FILTER('Table', [Months] = __Current)
        VAR __PrevMonthTable = FILTER('Table', [Months] = __PrevMonth)
        VAR __Result = COUNTROWS(__CurrentTable) - COUNTROWS(__PrevMonthTable)
    RETURN
        __Result

    But, to get it in the form that you are showing, you will need something like this: The New Hotness (Custom Matrix Hierarchy) - Microsoft Fabric Community

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    ksha_001 Should be something like this:

    Measure = 
        VAR __Current = MAX('Table'[Months])
        VAR __PrevMonth = MAXX(FILTER('Table', [Months] <> __Current), [Months])
        VAR __CurrentTable = FILTER('Table', [Months] = __Current)
        VAR __PrevMonthTable = FILTER('Table', [Months] = __PrevMonth)
        VAR __Result = COUNTROWS(__CurrentTable) - COUNTROWS(__PrevMonthTable)
    RETURN
        __Result

    But, to get it in the form that you are showing, you will need something like this: The New Hotness (Custom Matrix Hierarchy) - Microsoft Fabric Community

    • ksha_001's avatar
      ksha_001
      Regular Visitor

      Thank you Greg_Deckler . That worked. Regarding renaming the total field, I have a question. When I try to rename the field by right-clicking, the change doesn't reflect on the canvas. Is this a Power BI limitation?