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
oliharford
Regular Visitor

DAX query for grouping counts of claims by id and still impacted by date filter

Hi,

 

I have been really struggling with a concept to build a report which matches the requirements:

Number of installers with 0 claims

Number of installers with 1 claim

Number of Installer with 2 or more claims

 

 

This also needs to be affected by a time slicer.

 

The data I have is:

Users

UserId 
1
2
3
4
5
6
7

 

Claims

IdDateUserId
101/01/20222
227/01/20221
302/02/20222
420/03/20227

 

In the report one table we are trying to show is:

Count of useridClaim bracket
40
21
12+

 

Really hoping someone can help 🙂

 

Regards,

 

Oli

2 ACCEPTED SOLUTIONS
JirkaZ
Solution Specialist
Solution Specialist

The simplest way would be to create 3 different measures for that with the following logic:

SUMX(Users, IF(COUNTROWS(RELATEDTABLE(Claims)) = 0, 1, 0)
This will sum up all the users that have no claims during the slicer-selected time period. 

View solution in original post

vojtechsima
Memorable Member
Memorable Member

Hi, @oliharford@JirkaZ 
I believe I figured it out. The solution requires only one measure and Brackets Dimension Table:

vojtechsima_0-1650641231404.png

 

 

Brackets = 

var table___ = SUMMARIZE(Claims, Users[UserId ], "CountOfRequest", COUNTA(Claims[UserId]))
var _Add_ = ADDCOLUMNS(table___, "UserIDUnique", Users[UserId ], "CountOfRequestPerUser", [CountOfRequest], "Brackets_", SWITCH(TRUE(), [CountOfRequest] >= 2, "2+", [CountOfRequest] = 1, "1", "0"))

var currentBrackets = MAX(ClaimBrackets[Brackets])

var AllUsers = COUNTROWS(VALUES(Users[UserId ]))
var UsersWith2Plus = COUNTROWS(FILTER(_Add_, [CountOfRequest]>=2))
var UsersWith1 = COUNTROWS(FILTER(_Add_, [CountOfRequest]=1))
var UserWith0 = AllUsers - (UsersWith2Plus + UsersWith1)



var returnCount = SWITCH(TRUE(), 
currentBrackets = "2+", UsersWith2Plus,
currentBrackets = "1", UsersWith1,
UserWith0)

return returnCount

 

 

vojtechsima_1-1650641265842.png

 

 

View solution in original post

3 REPLIES 3
vojtechsima
Memorable Member
Memorable Member

Hi, @oliharford@JirkaZ 
I believe I figured it out. The solution requires only one measure and Brackets Dimension Table:

vojtechsima_0-1650641231404.png

 

 

Brackets = 

var table___ = SUMMARIZE(Claims, Users[UserId ], "CountOfRequest", COUNTA(Claims[UserId]))
var _Add_ = ADDCOLUMNS(table___, "UserIDUnique", Users[UserId ], "CountOfRequestPerUser", [CountOfRequest], "Brackets_", SWITCH(TRUE(), [CountOfRequest] >= 2, "2+", [CountOfRequest] = 1, "1", "0"))

var currentBrackets = MAX(ClaimBrackets[Brackets])

var AllUsers = COUNTROWS(VALUES(Users[UserId ]))
var UsersWith2Plus = COUNTROWS(FILTER(_Add_, [CountOfRequest]>=2))
var UsersWith1 = COUNTROWS(FILTER(_Add_, [CountOfRequest]=1))
var UserWith0 = AllUsers - (UsersWith2Plus + UsersWith1)



var returnCount = SWITCH(TRUE(), 
currentBrackets = "2+", UsersWith2Plus,
currentBrackets = "1", UsersWith1,
UserWith0)

return returnCount

 

 

vojtechsima_1-1650641265842.png

 

 

JirkaZ
Solution Specialist
Solution Specialist

The simplest way would be to create 3 different measures for that with the following logic:

SUMX(Users, IF(COUNTROWS(RELATEDTABLE(Claims)) = 0, 1, 0)
This will sum up all the users that have no claims during the slicer-selected time period. 

Amazing thank you for this, such a simple solution  for something i have really struggled with.

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.