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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
ILANGO_10
Frequent Visitor

How to add a value from last result under conditions

IMG_20230209_162602.jpg

 in this problem I need that needed column in power bi.. condition is in that type column if there is KT the seq no is print but there is no KT in type  there are two conditions the mat and before mat is same then add needed last answer and quantity if two conditions are false just print 10;.... If you can't get my problem please see the Excel formula... I hope u can understand my problem.. and please help me with it.... 

5 REPLIES 5
ronrsnfld
Super User
Super User

You can use the List.Generate function in a Table.Group aggregation to generate that extra column:

let

//change next line to reflect data source
    Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"mat", type text}, {"seq no", Int64.Type}, {"type", type text}, {"quantity", Int64.Type}}),

//Group rows by mat
    #"Grouped Rows" = Table.Group(#"Changed Type", {"mat"}, {
        {"needed", (t)=> 
            Table.FromColumns(
                Table.ToColumns(t) &
                {List.Generate(
                    ()=>[n=if t[type]{0}="KT" then t[seq no]{0} else 10, idx=0],
                    each [idx] < Table.RowCount(t),
                    each [n=if t[type]{[idx]+1}="KT" then t[seq no]{[idx]+1} else [n]+t[quantity]{[idx]+1} , idx=[idx]+1],
                    each [n])},
                Table.ColumnNames(t) & {"needed"})
            }}),
            
    #"Expanded needed" = Table.ExpandTableColumn(#"Grouped Rows", "needed", {"seq no", "type", "quantity", "needed"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded needed",{{"seq no", Int64.Type}, {"type", type text}, {"quantity", Int64.Type}, {"needed", Int64.Type}})
in
    #"Changed Type1"

 

ronrsnfld_0-1675994682424.png

 

 

Can you tell me how to do in dax functions or measures....

Isn't there a DAX forum? I thought this was for Power Query. In any event, it's not something I'd be able to get to any time soon.

wdx223_Daniel
Super User
Super User

=Table.FromRows(List.Accumulate(Table.ToRows(PreviousStepName),{{},"",0},(x,y)=>let a=if y{2}="KT" then y{1} else if y{0}=x{1} then y{3}+x{2} else 10 in {x{0}&{y&{a}},y{0},a}){0},Table.ColumnNames(PreviousStepName)&{"needed"})

Can you tell me how to do in dax functions or measures....

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Solution Authors