Sum the latest data without blank values for each suppliers - Power BI

Danoob

New Member
Joined
May 31, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm looking for a way to filter values in a matrix table with the latest month with no blank rows
To give you an quick explanation I have :
- 1 dedicated date table with month, year, etc....
- 1 data table with different suppliers and the amount they delivered.

For example in the table below Supp 2 didn't deliver for month 3 so I would like to display month 2 total only for Section 1.
If anyone have a recommendation or the glance of an idea I would be very grateful

Thanks,

Month
1
2
3
Section 1
Supp1
50​
20​
30​
Supp2
50​
60​
Total
100
80
30
Section 2
Supp4
50​
60​
200​
Supp3
70​
80​
10​
Total
120
140
210
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    tbl = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    tbl1 = Table.SelectRows(tbl, each ([Month] <> "Total")),
    tbl2 = Table.AddColumn(tbl1, "Section", each if Text.Start([Month],7) = "Section" then [Month] else null),
    tbl3 = Table.FillDown(tbl2,{"Section"}),
    tbl4 = Table.SelectRows(tbl3, each not Text.StartsWith([Month], "Section")),
    tbl5 = Table.Group(tbl4, {"Section"}, {"All", each _}),
    tbl6 = Table.TransformColumns(tbl5, {"All", each Table.AddColumn(_, "LastFullMonth", (x)=> let lpo = List.PositionOf(Record.ToList(x), null) in if lpo = -1 then 999 else lpo)}),
    tbl7 = Table.AddColumn(tbl6, "Month", each let min = List.Min([All][LastFullMonth]) in if min = 999 then Table.ColumnNames([All]){Table.ColumnCount([All]) - 3} else Table.ColumnNames([All]){min -1}),
    tbl8 = Table.AddColumn(tbl7, "Total", each List.Sum(List.Transform(Table.Column([All], [Month]), (x)=> Number.From(x)))),
    Result = Table.RemoveColumns(tbl8,{"All"})
in
    Result

Book1
ABCDEFGHI
1Column1Column2Column3Column4SectionMonthTotal
2Month123Section 1280
3Section 1Section 23210
4Supp1502030
5Supp25060
6Total1008030
7Section 2
8Supp45060200
9Supp3708010
10Total120140210
11
Sheet3
 
Upvote 1
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    tbl = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    tbl1 = Table.SelectRows(tbl, each ([Month] <> "Total")),
    tbl2 = Table.AddColumn(tbl1, "Section", each if Text.Start([Month],7) = "Section" then [Month] else null),
    tbl3 = Table.FillDown(tbl2,{"Section"}),
    tbl4 = Table.SelectRows(tbl3, each not Text.StartsWith([Month], "Section")),
    tbl5 = Table.Group(tbl4, {"Section"}, {"All", each _}),
    tbl6 = Table.TransformColumns(tbl5, {"All", each Table.AddColumn(_, "LastFullMonth", (x)=> let lpo = List.PositionOf(Record.ToList(x), null) in if lpo = -1 then 999 else lpo)}),
    tbl7 = Table.AddColumn(tbl6, "Month", each let min = List.Min([All][LastFullMonth]) in if min = 999 then Table.ColumnNames([All]){Table.ColumnCount([All]) - 3} else Table.ColumnNames([All]){min -1}),
    tbl8 = Table.AddColumn(tbl7, "Total", each List.Sum(List.Transform(Table.Column([All], [Month]), (x)=> Number.From(x)))),
    Result = Table.RemoveColumns(tbl8,{"All"})
in
    Result

Book1
ABCDEFGHI
1Column1Column2Column3Column4SectionMonthTotal
2Month123Section 1280
3Section 1Section 23210
4Supp1502030
5Supp25060
6Total1008030
7Section 2
8Supp45060200
9Supp3708010
10Total120140210
11
Sheet3
Hello thanks a lot for you help. However I'm wondering if it is possible to do such but with DAX ? Beause my table on top is not directly presented like this in Power query. Looking forward to your answer. Many thanks
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,872
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top