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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Sum various columns based on a condition set upon another group of columns

Hi all,

 

 

I am relatively new to Power BI and am having issues working out how to filter and sum a set of columns based on the value in one slicer. It is rather difficult to explain the issue, therefore I would like to define my problem by giving the below example.

 

Lets say I have the following sets of data:

 

Event data

FlightDelay Reason 1Delay Reason 2Delay Reason 3Delay Amount 1Delay Amount 2Delay Amount 3
00013851272
00023  63  
000319 93 
More Data

 

Delay Categories

CategoryCode
A1
A2
B3
B4
B5
B6
B7
C8
C9
C10

 

 

Now I would like the user to be able to filter one or more Categories and then calculated the total delay (at flight level) for all related delays and subsequently determine the number of flights that had less than 20 minutes delay.

 

 

For example if the user selected Category B (Codes: 3,4,5,6,7) then the data returned would be:

 

Event data (Filtered for Category B)

 

FlightDelay Reason 1Delay Reason 2Delay Reason 3Delay Amount 1Delay Amount 2Delay Amount 3Delay Total
00013851272 14
00023  63   63
0003Deleted
More Data

 

The total number of flights with a delay greater than 20 minutes would only be one as the delay minutes attributed to Delay Reason 2 are not included.

 

 

I have tried to create a relationships between Delay Categories (Table) and Delay Reason 1, Delay Reason 2 and Delay Reason 3. However Power BI will only allow me to keep one active at all times.

 

Please note that pivotting the table to show all delay reasons in 1 column did not work as I only wanted a flight to count once (Flight 0001 in the above example).

 

 

Please let me know if there is a simple solution.

 

 

 

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may use SELECTCOLUMNS Function (DAX) and UNION Function to add a calculated table.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

First, I would suggest unpivoting your Delay Reason columns in the Query Editor. Next question, are your Codes (1, 2, 3, 4...) really mismatched from your Column headings (Delay Reason 1, Delay Reason 2,...)? Should not be an issue either way but changes the solution.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg,

Thanks for your reply. The data itself comes like that in its raw form, but I’m more than happy to unpivot it. However I’ll need to find a way to sum up the delay total at a flight level basis once done.

Regarding the relationship between the categories... they are exactly as shown in the table. In the raw data set the delay codes willl be associated to a delay category, I.e codes 1-3 is related to weather, 4-9 ground handling, etc

Hope that helps?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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