The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi everyone,
I have an issue concerning summing columns in PoerBI.
Basically I have rows, where columns are MondayHours, TuesdayHours, WednesdayHours..... , MondayDate, TuesdayDate.... MondayMonthYear, TuesdayMonthYear.
E.g. I want to sum: MondayHours IF MondayMonthYear = April 2022 +TuesdayHours IF TuesdayMonthYear = April 2022. As a result I want a column name called April2022, then May2022....
Could you please help me how to make it happen?
Thanks in advance!
Solved! Go to Solution.
Hi @dataFreak ,
To perform such calculations in powerbi, you need to first convert the data model that dax can recognize by power query. Refer to an attempt like the following:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJV0lEyswARZiYwpiUQGxsZgFhmxkqxOtFKxsZAjpEZVM4MpMnIGMQ1tjQyAaszVYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Mon = _t, Tue = _t, Wed = _t, Thu = _t, Fri = _t, #"2021-01" = _t, #"2021-02" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Mon", Int64.Type}, {"Tue", Int64.Type}, {"Wed", Int64.Type}, {"Thu", Int64.Type}, {"Fri", Int64.Type}, {"2021-01", Int64.Type}, {"2021-02", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Date"}})
in
#"Renamed Columns"
M = CALCULATE(SUM('Table (2)'[Value]),'Table (2)'[Date]="Mon")
If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @dataFreak ,
To perform such calculations in powerbi, you need to first convert the data model that dax can recognize by power query. Refer to an attempt like the following:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJV0lEyswARZiYwpiUQGxsZgFhmxkqxOtFKxsZAjpEZVM4MpMnIGMQ1tjQyAaszVYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Mon = _t, Tue = _t, Wed = _t, Thu = _t, Fri = _t, #"2021-01" = _t, #"2021-02" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Mon", Int64.Type}, {"Tue", Int64.Type}, {"Wed", Int64.Type}, {"Thu", Int64.Type}, {"Fri", Int64.Type}, {"2021-01", Int64.Type}, {"2021-02", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Date"}})
in
#"Renamed Columns"
M = CALCULATE(SUM('Table (2)'[Value]),'Table (2)'[Date]="Mon")
If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If you unpivot the columns, the calculations will be simplified. Here's a post that shows how:
https://community.powerbi.com/t5/Desktop/Unpivot-in-Power-Query/m-p/2186044
Proud to be a Super User!
User | Count |
---|---|
58 | |
56 | |
55 | |
50 | |
32 |
User | Count |
---|---|
171 | |
87 | |
70 | |
46 | |
45 |