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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.