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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
SteveCS
Frequent Visitor

Multiple columns needed in switch function.

Hi, I have matrix that  shows a breakdown of days, using the following switch() function

SteveCS_0-1740762474656.png

Aging_At_Activity Split =
   VAR DaysDifference = 'NurseTAT'[Aging_At_Activity]
   //AGCI.RECEIVED_DATE,ACT.[CREATED_ON]
   RETURN
       SWITCH(
           TRUE(),
           DaysDifference <= 0, "1< day",
           DaysDifference >= 1 && DaysDifference <= 3, "1-3 days",
           DaysDifference >= 4 && DaysDifference <= 6, "4-6 days",
           DaysDifference >= 7 && DaysDifference <= 9, "7-9 days",
           DaysDifference > 9 , "9> days"
       )
 
I use the count function to show how many are in each bucket.  But I'm trying to find a way to add in an additional field to this switch, so that each columns shows a breakdown by % against the total, as well?
I've tried building it but I keep running into errors.

Help is appreciated.
Thanks, SteveCS
5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.  Should the denominator be the column total, row total or the grand total?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
SteveCS
Frequent Visitor

So basically You cannot create multiple columns of different data sources using the switch....You can only work with one field at a time (other than using multiple fields in parameters.

Akash_Varuna
Community Champion
Community Champion

Hi @SteveCS Please try these out 

  1. Create a measure for the total count:

    Total Count = COUNTROWS('YourTableName')
  2. Keep your Aging_At_Activity Split calculation as is.

  3. Create a measure for each bucket's count:

    Count Bucket Days = 
    CALCULATE(
        COUNTROWS('YourTableName'),
        'YourTableName'[DaysDifference] >= 1 && 'YourTableName'[DaysDifference] <= 3
    )
  4. Create percentage measures for each bucket:

    Percent Bucket Days = 
    DIVIDE([Count 1-3 Days], [Total Count], 0)
  5. Add the counts and percentages to your matrix.

Thank for this. But does this allow me to have a matrix where the columns visually appear as 

Count | Percentage| Count | Percentage | count | percentage | total 

You will have to create a custom table along with the above and then union all the above into that table

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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