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
deb_power123
Helper V
Helper V

How to get Total in Table Matrix based using Calculated measure or column?

Hi,

 

In my input data I have the following columns: Date, TotalSeats,OccupiedSeats,SchoolName and Buildings.

 

 I want to show the  (sum of Occupied Seats/sum of Total Seats )per school and its percentageas highlighted in yellow color 'Total Occupied' and '%Occupied' in the expected output below.

 

Can someone suggest any DAX to achieve this?Can we handle that using calculated DAX measure or column? Please provide your suggestions.

 

[ P.S: ROW TOTAL and GRAND TOTAL properties doesnt serve the purpose here, they will simply add  and sum up all the %ge occupied seats so in that case it can be more than 100% if its simple additon if %Ocupied seats is aound 95% or more each building so we want sum TotalSeats/sum ocupied seats per building.]

 

 

My Input sample data :-

Date  TotalSeatsOccupiedSeatsSchool NameBuildings
21-03-2021        101School1Building1
22-03-2021        104School1Building1
23-03-2021        104School1Building1
24-03-2021        101School1Building1
25-03-2021        102School1Building1
26-03-2021        101School1Building1
27-03-2021        101School1Building1
21-03-2021        125School1Building2
22-03-2021        128School1Building2
23-03-2021        128School1Building2
24-03-2021        123School1Building2
25-03-2021        124School1Building2
26-03-2021        122School1Building2
27-03-2021        124School1Building2

 

In my visualization, I can show every of the below table matrix except the one higlighted in yellow.

 

Expected Output should look like this in table matrix:-

expected.jpg

1 ACCEPTED SOLUTION
v-yuaj-msft
Community Support
Community Support

Hi @deb_power123 ,

 

Based on your description, I did a test. Is the following result what you want?

v-yuaj-msft_0-1618286989772.png

Here are the steps.

1. create a calculated column

Column = IF(RIGHT([Buildings],1)="1",[OccupiedSeats],[OccupiedSeats]-MINX(FILTER(ALL('Test_sum'),[Date]=EARLIER('Test_sum'[Date])),[OccupiedSeats]))
2. create a measure
Measure = DIVIDE(SUM('Test_sum'[Column]),SUM('Test_sum'[ TotalSeats]))
3. create a matrix.
v-yuaj-msft_1-1618287088285.png

4. set "grand total" in Format pane.

v-yuaj-msft_2-1618287171541.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

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

7 REPLIES 7
v-yuaj-msft
Community Support
Community Support

Hi @deb_power123 ,

 

Based on your description, I did a test. Is the following result what you want?

v-yuaj-msft_0-1618286989772.png

Here are the steps.

1. create a calculated column

Column = IF(RIGHT([Buildings],1)="1",[OccupiedSeats],[OccupiedSeats]-MINX(FILTER(ALL('Test_sum'),[Date]=EARLIER('Test_sum'[Date])),[OccupiedSeats]))
2. create a measure
Measure = DIVIDE(SUM('Test_sum'[Column]),SUM('Test_sum'[ TotalSeats]))
3. create a matrix.
v-yuaj-msft_1-1618287088285.png

4. set "grand total" in Format pane.

v-yuaj-msft_2-1618287171541.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

mahoneypat
Employee
Employee

You can use this measure expression to get both your individual values and the correct values in the total rows.  Use it in a matrix or table with the School and Building columns.

 

Pct Occupied =
AVERAGEX (
    SUMMARIZE ( Seats, Seats[Buildings], Seats[School Name] ),
    CALCULATE (
        DIVIDE ( SUM ( Seats[OccupiedSeats] )SUM ( Seats[  TotalSeats] ) )
    )
)

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi @mahoneypat The only issue i am facing is that using DAX it is not showing one Total row but each of the  buildings has its total row for %occupancy and also the ratio format is replaced with decimal format.I wanted to show in ratio  format using concatenation function.

 

The one below in red color is expected result and format .I want to show in ratio format but the DAX you suggested shows the results in decimal format and it shows total not in one row but under each building row like for Building1 and Building2 we have seperate Total instead of one total.Could you please suggest?

 

expected.jpg

Please try this measure instead for your Total Occupied

 

Ratio Occupied = var occupied = SUM(Seats[OccupiedSeats])
var totalseats = SUM(Seats[ TotalSeats])
return occupied & "|" & totalseats
 
Regards,
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@deb_power123 , You can create two measures occupied and occupied % and in matrix, you can use the option "Show on row"

 

I am not sure you can get exact same output

https://www.burningsuit.co.uk/blog/2019/04/7-secrets-of-the-matrix-visual/

I didnt get you, which two measures you are stating here.Can you please elaborate? I need some DAX measure to be created to get the  (sum of Occupied Seats/sum of Total Seats )per school.

I am not sure how to achieve this DAX, could you guide

@deb_power123 , Try like

divide(sum(Table[OccupiedSeats]), calculate(sum(Table[OccupiedSeats]), filter(allselected(Table), Table[School Name] = max(Table[School Name ]) && Table[Buildings] = max(Table[Buildings]))))

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.