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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
dataFreak
New Member

Sum of different columns under condition

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!

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

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")

vhenrykmstf_1-1651822225776.png

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.

View solution in original post

2 REPLIES 2
v-henryk-mstf
Community Support
Community Support

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")

vhenrykmstf_1-1651822225776.png

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.

DataInsights
Super User
Super User

@dataFreak,

 

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.