Forum Discussion
Filter and Count
- 4 months ago
Hi AllanBerces,
You can achieve it by creating a calculated column first to define buckets and then create all the measures separately for each bucket and for count. also create a month column.
I've created a sample for you, Please take a look.
π I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
π‘ Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
π As a proud SuperUser and Microsoft Partner, weβre here to empower your data journey and the Power BI Community at large.
π Curious to explore more? [Discover here].
Letβs keep building smarter solutions together! - 4 months ago
Hi AllanBerces
You can do it, but the bucket logic needs to be fixed first.
The four conditions you listed do not cover all possible values, so they will not add up to your total measure. In your sample data, for example, there are several rows with a value of 48, and those are not included in any of your current buckets.
Right now your groups are:
less than 48
equal to 72
equal to 96
greater than 96That leaves out values such as 48, and also anything between 49β71 or 73β95 if those exist in the data.
If you want the sum of all category measures to match your total, each row must belong to one and only one bucket.
For example, you could create measures like these:
Count S-08 < 48 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] < 48
)
)
)
Count S-08 = 48 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] = 48
)
)
)
Count S-08 = 72 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] = 72
)
)
)
Count S-08 = 96 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] = 96
)
)
)
Count S-08 > 96 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] > 96
)
)
)A cleaner approach would be to create a bucket column first, then use that bucket in the visual instead of creating many separate measures.
Example:
S-08 Bucket =
SWITCH(
TRUE(),
'Table'[Day Difference S-08 -S-09/10] < 48, "<48",
'Table'[Day Difference S-08 -S-09/10] = 48, "48",
'Table'[Day Difference S-08 -S-09/10] = 72, "72",
'Table'[Day Difference S-08 -S-09/10] = 96, "96",
'Table'[Day Difference S-08 -S-09/10] > 96, ">96",
"Other"
)Then you can simply count rows by that bucket.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Hi AllanBerces
You can do it, but the bucket logic needs to be fixed first.
The four conditions you listed do not cover all possible values, so they will not add up to your total measure. In your sample data, for example, there are several rows with a value of 48, and those are not included in any of your current buckets.
Right now your groups are:
less than 48
equal to 72
equal to 96
greater than 96
That leaves out values such as 48, and also anything between 49β71 or 73β95 if those exist in the data.
If you want the sum of all category measures to match your total, each row must belong to one and only one bucket.
For example, you could create measures like these:
Count S-08 < 48 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] < 48
)
)
)
Count S-08 = 48 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] = 48
)
)
)
Count S-08 = 72 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] = 72
)
)
)
Count S-08 = 96 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] = 96
)
)
)
Count S-08 > 96 =
SUMX(
VALUES('Index Month'[Month]),
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
MONTH('Table'[S-08]) = SELECTEDVALUE('Index Month'[Month Index]) &&
'Table'[Day Difference S-08 -S-09/10] > 96
)
)
)
A cleaner approach would be to create a bucket column first, then use that bucket in the visual instead of creating many separate measures.
Example:
S-08 Bucket =
SWITCH(
TRUE(),
'Table'[Day Difference S-08 -S-09/10] < 48, "<48",
'Table'[Day Difference S-08 -S-09/10] = 48, "48",
'Table'[Day Difference S-08 -S-09/10] = 72, "72",
'Table'[Day Difference S-08 -S-09/10] = 96, "96",
'Table'[Day Difference S-08 -S-09/10] > 96, ">96",
"Other"
)
Then you can simply count rows by that bucket.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Hi Ritaf1983 just follow up question it doesnot give the correct Total, how can i correct it
Thank you