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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Grap first value above running total

Hi

I have the below table that shows the running total for a given values.

I want the query to check for the first value of VOR when running total exceeded the capacity.

 

above capacity.JPG

 

4 REPLIES 4
wdx223_Daniel
Super User
Super User

M Code

NewStep=Table.Group(PreviousStepName,"WM",{"VOR",each Table.Skip(_,each [Capacity]>=[#"Running Total"]){0}?[VOR]?})

DAX Code

NewMeasure=FIRSTNONBLANK(VALUES[Table[WM],IF(CALCULTE(MAX(Table[Capacity])<MAX(Table[Running Total])),1))

mussaenda
Super User
Super User

Hi @Anonymous ,

 

Have you tried the if else condition?

mussaenda_0-1697526671274.png

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc47EoAwCATQu1Cn4JNAcghri0zufw1RR4XCArZ4xe6csG9IUMD82BDPwGqwykvMwZpqMgmmPZmMYJ0kWqPPRKQ9dlf5I8QLbeD4xU4joVBAz85JJSqjb4iqUaua710H", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [WM = _t, VOR = _t, CAPACITY = _t, #"RUNNING TOTAL" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"WM", type text}, {"VOR", Int64.Type}, {"CAPACITY", Int64.Type}, {"RUNNING TOTAL", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [RUNNING TOTAL] > [CAPACITY]
or [RUNNING TOTAL] > [CAPACITY]
then 1 else 
0),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"WM", "Custom"}, {{"Count", each _, type table [WM=nullable text, VOR=nullable number, CAPACITY=nullable number, RUNNING TOTAL=nullable number, Custom=number]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom.1", each Table.AddIndexColumn([Count], "Index", 1, 1)),
    #"Expanded Custom.1" = Table.ExpandTableColumn(#"Added Custom1", "Custom.1", {"VOR", "CAPACITY", "RUNNING TOTAL", "Index"}, {"VOR", "CAPACITY", "RUNNING TOTAL", "Index"}),
    #"Added Custom2" = Table.AddColumn(#"Expanded Custom.1", "Custom.1", each if [Custom] = 1
and [Index] = 1 
then [VOR]
else null),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"WM", "VOR", "CAPACITY", "RUNNING TOTAL", "Custom.1"})
in
    #"Removed Other Columns"
watkinnc
Super User
Super User

Just GroupBy "WM" and choose the Max aggregation for Running Total.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
Anonymous
Not applicable

Unfortunately, it didn't work!

This is not max, but above certain value! and I want the corresponded column value.

Helpful resources

Announcements
Europe Fabric Conference

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.

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