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
nirrobi
Helper V
Helper V

POWER QEURY move from cumulaive to line aomunt

Hi,

 

I have table with cumulative data - 2 M rows

what is the best way to add line amount column that reflect the line amount (ExpectedReslt in the table below)

 

 

attach sample data with expected result

CategoryReferanceCumulativeExpectedReslt
A122
A242
A384
B111
B221
B331
C110

10



5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

It is quite somple to solve this with a calculated column formula using DAX.  Would you be interested?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Yes please

 

please be notet that my relevant table is 2,000,000 rows so the formula should be super effective:-)

Hi,

This calculated column formula works

=if(ISBLANK(CALCULATE(max(Data[Referance]),FILTER(Data,Data[Category]=EARLIER(Data[Category])&&Data[Referance]<EARLIER(Data[Referance])))),Data[Cumulative],LOOKUPVALUE(Data[Cumulative],Data[Category],Data[Category],Data[Referance],CALCULATE(max(Data[Referance]),FILTER(Data,Data[Category]=EARLIER(Data[Category])&&Data[Referance]<EARLIER(Data[Referance])))))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Zubair_Muhammad
Community Champion
Community Champion

@nirrobi 

 

Here is a way of doing it in Power Query.

See file attached as well.

Basically I created another custom column as Reference -1 and then merged it with current Reference Column to get previous cumulative

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYiMwjtWBiIB4JigixkBsARYFiThBdUEwTMQIihEixlAMEXGG6TCAELGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Category = _t, Referance = _t, Cumulative = _t, ExpectedReslt = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Referance", Int64.Type}, {"Cumulative", Int64.Type}, {"ExpectedReslt", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Referance]-1),
    #"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Category", "Custom"}, #"Added Custom", {"Category", "Referance"}, "Added Custom", JoinKind.LeftOuter),
    #"Expanded Added Custom" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Cumulative"}, {"Added Custom.Cumulative"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Added Custom", "DesiredResult", each if [Added Custom.Cumulative]= null then [Cumulative] else[Cumulative]-[Added Custom.Cumulative]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom", "Added Custom.Cumulative"})
in
    #"Removed Columns"

Regards
Zubair

Please try my custom visuals

great !!

many thanks

 

I will check of 2 M rows table and let you know

 

I tried somethong similar (but diff) but the engine couldn't complete the calculation

 

10x

 

 

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.