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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Month on Month Difference

Hi everyone! 

 

I am having trouble digging out a formula to get the month on month difference for each Account Number.

 

My data is structed as below:

 

AccountDateLimitDifference
107/05/2019 €        8,000 
207/05/2019 €        5,000 
307/05/2019 €        1,000 
115/06/2019 €        6,000 
215/06/2019 €        7,000 
315/06/2019 €        3,000 
112/07/2019 €        9,000 
212/07/2019 €        6,000 
312/07/2019 €        5,000 

 

 

My issue is how to find the difference in the limit's for each account and how it differs month to month.

 

Can anyone please help? I would greatly appreciate it.

 

Thank you

 

Water

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Have you tested my solution? If my answer is useful, please accept my reply.Thanks!

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

3 REPLIES 3
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

At first, you need to use the following codes in query editor to get a suitable table.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckxOzi/NK1HSUXJJLEkFUj6ZuZlgbmZaWmpRal5yqlKsTrSSIVDIyMDQUtdU1xzIVHjUtEYBCix0DAwMQGJghUa4FZqiKDTGrdAQRSHcajNdQ1M0lWbY7cai0hy75VhUGmO33VzX0AhNpSV227GoNMNuOxaVSIEUCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Account", Int64.Type}, {"Date", type text}, {"Limit", type text}, {"Difference", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Difference"}),
    #"Replaced Value" = Table.ReplaceValue(#"Removed Columns","        ","",Replacer.ReplaceText,{"Limit"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","€","",Replacer.ReplaceText,{"Limit"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1",",","",Replacer.ReplaceText,{"Limit"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Replaced Value2",{{"Limit", type number}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type2", {{"Account", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type2", {{"Account", type text}}, "en-US")[Account]), "Account", "Limit", List.Sum),
    #"Added Index" = Table.AddIndexColumn(#"Pivoted Column", "Index", 1, 1)
in
    #"Added Index"

Then you will get a table.2-1.PNG

Now you can create columns to calculate differences.

Compare1to2 =
'Table'[1] - 'Table'[2]
Compare2to3 =
'Table'[2] - 'Table'[3]
Compare1to3 =
'Table'[1] - 'Table'[3]
D1 =
VAR p =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[1], 1 ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    )
RETURN
    IF ( p <> BLANK (), 'Table'[1] - p )
D2 =
VAR p =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[2], 1 ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    )
RETURN
    IF ( p <> BLANK (), 'Table'[2] - p )
D3 =
VAR p =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[3], 1 ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    )
RETURN
    IF ( p <> BLANK (), 'Table'[3] - p )

The final table:

2-2.PNG

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

Wow!

 

Thank you for such a thorough answer.

 

The solution is too complicated for me to implement but I appreciate your time and effort nonetheless.

 

Thank you

 

Stay Hydrated

Hi @Anonymous ,

 

Have you tested my solution? If my answer is useful, please accept my reply.Thanks!

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.