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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
sebastianslzr
Regular Visitor

How to solved error when I am using percentages in a matrix

I have the following data source where I have to count by visit date the times that a process has passed through each month in each state, applying the visit date as the main filter for the following example I do it with the month of April.

The following is the data source I use.

CityLocationNameVisit DateStatusEnroll MonthEnroll Year
Salt LakeCapitol BuildingRhoda Horton27-05-23OpenMay2023
Salt LakeCapitol BuildingRhoda Horton27-05-23ProgressMay2023
Salt LakeCapitol BuildingRhoda Horton27-05-23CanceledMay2023
Salt LakeCapitol BuildingRhoda Horton27-05-23ClosedMay2023
Salt LakeCapitol BuildingBarry Parrish28-04-23OpenApril2023
Salt LakeCapitol BuildingBarry Parrish28-04-23ProgressApril2023
Salt LakeCapitol BuildingBarry Parrish28-04-23CanceledApril2023
Salt LakeCapitol BuildingBarry Parrish28-04-23ClosedMay2023
Salt LakeRed Butte GardenCarolyn Hogan25-04-23OpenApril2023
Salt LakeRed Butte GardenCarolyn Hogan25-04-23ProgressMay2023
Salt LakeRed Butte GardenCarolyn Hogan25-04-23CanceledMay2023
Salt LakeRed Butte GardenCarolyn Hogan25-04-23ClosedJune2023
Salt LakeCapitol BuildingFarrah Gray23-04-23OpenApril2023
Salt LakeCapitol BuildingFarrah Gray23-04-23ProgressAugust2023
Salt LakeCapitol BuildingFarrah Gray23-04-23CanceledAugust2023
Salt LakeCapitol BuildingFarrah Gray23-04-23ClosedAugust2023

 

To count the number of times a process has been in each month based on the date of visit, I use the following measure:

Total Proc. Open = COUNTROWS(FILTER(Table1,Table1[STATUS] = "Open")


The same goes for each of the different Status:

Total Proc. Progress = COUNTROWS(FILTER(Table1,Table1[STATUS] = "Progress")) 
Total Proc. Canceled = COUNTROWS(FILTER(Table1,Table1[STATUS] = "Canceled"))
Total Proc. Closed = COUNTROWS(FILTER(Table1,Table1[STATUS] = "Closed"))

To make all this data fit the matrix I'm making, I use an additional measure where I make use of a Switch:

Measure Status =
    SWITCH(VALUES(Table1[STATUS]),
    "Open",[Total Proc. Open],
    "Progress",[Total Proc. Progress],
    "Canceled",[Total Proc. Canceled],
    "Closed",[Total Proc. Closed])

So far everything is working correctly for me and the data is displayed correctly as I want in the following matrix:

sebastianslzr_0-1714501506465.png

The error happens when I want to show the percentages of the previous data in a new matrix, i.e. I want them to be displayed as follows:

sebastianslzr_1-1714501607583.png

For the calculation of the percentages in the matrix, I have done something similar to the previous matrix where I use a Switch, the measure is as follows:

Percentage Measure = 
SWITCH(VALUES(Table1[STATUS]),
"Open","100%",
"Progress",DIVIDE(CALCULATE(COUNTROWS(Table1),Table1[STATUS] = "Progress"),CALCULATE(COUNTROWS(Table1),Table1[STATUS] = "Open")),
"Canceled",DIVIDE(CALCULATE(COUNTROWS(Table1),Table1[STATUS] = "Canceled"),CALCULATE(COUNTROWS(Table1),Table1[STATUS] = "Open")),
"Closed",DIVIDE(CALCULATE(COUNTROWS(Table1),Table1[STATUS] = "Closed"),CALCULATE(COUNTROWS(Table1),Table1[STATUS] = "Open")))

When using the previous measure it only shows me the percentages of the month that I have selected in the filter and does not show me the others, an example below of what is shown is the following:

sebastianslzr_2-1714501854383.png

Are there any changes I need to make to my measure to achieve the goal?

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

Hi @sebastianslzr ,

 

The unexpected result you obtained is because there is a problem with counting the status of open, as shown in the figure below. At this time, only April has open data, so only the data of April will be displayed in the matrix.

vkaiyuemsft_0-1714532461487.png

 

You can use the ALLSELECTED function to change the context and obtain the desired results.

Measure =
VAR _count1 = CALCULATE(COUNTROWS('Table1'))
VAR _count2 = CALCULATE(COUNTROWS('Table1'),FILTER(ALLSELECTED('Table1'),'Table1'[Status] = "Open"))
RETURN
DIVIDE(_count1,_count2)

 

vkaiyuemsft_1-1714532492950.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

1 REPLY 1
v-kaiyue-msft
Community Support
Community Support

Hi @sebastianslzr ,

 

The unexpected result you obtained is because there is a problem with counting the status of open, as shown in the figure below. At this time, only April has open data, so only the data of April will be displayed in the matrix.

vkaiyuemsft_0-1714532461487.png

 

You can use the ALLSELECTED function to change the context and obtain the desired results.

Measure =
VAR _count1 = CALCULATE(COUNTROWS('Table1'))
VAR _count2 = CALCULATE(COUNTROWS('Table1'),FILTER(ALLSELECTED('Table1'),'Table1'[Status] = "Open"))
RETURN
DIVIDE(_count1,_count2)

 

vkaiyuemsft_1-1714532492950.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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