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

DAX Calculation for Aggregated values inside single table

Hi all,

I need a little DAX help!

 

I have the following table structure:

 

CustomerNIDAgentCount
AAA158974571
AAA678452174
AAA585792483
AAA824657524
BBB558824712
BBB845111981
CCC939702542
CCC158974572
CCC678452172
CCC585792482
CCC824657522
CCC768824712
CCC845111982
DDD809702541
EEE958974572
FFF478452173
FFF385792484
FFF124657523
FFF258824712
FFF346811973
FFF939154541
FFF465785764

 

(NID is unique)

 

I need help with 2 calculations:

 

Calc1 = find/count up where only 1 instance of the customer / All Customers

Calc2 = find/count NIDs where agentcount = 1/ ALL NIDs

 

This is really making my head scratch as it appears to be quite simple, but I cant seem to figure it out Smiley Frustrated

1 ACCEPTED SOLUTION

Hi @rax99,

Based on my test, you could refer below steps to get the Calc1:

Create a calculated column:

Column = CALCULATE(COUNT(Table1[Customer]),FILTER('Table1','Table1'[Customer]=EARLIER(Table1[Customer])))

1.PNG

Create a measure and you could get the correct result:

Calc1 = CALCULATE(COUNT(Table1[Column]),FILTER('Table1',Table1[Column]=1))/DISTINCTCOUNT(Table1[Customer])

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
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

5 REPLIES 5
PattemManohar
Community Champion
Community Champion

@rax99 Your expected output wasn't clear. Could you please post the expected output data as well as per sample input data.





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




So just to clarify, from the sample table above.

 

Calc1:

- There are just 2 customers where there is only a single instance of them, "DDD" and "EEE".

- In total there are 6 unique customers, AAA, BBB, CCC, DDD, EEE, and FFF.

- Expected result is (2/6) = 33.33%

 

Calc 2:

-There are 4 NIDs that have a AgentCount of 1, NIDs. 15897457, 84511198, 80970254, 93915454

- There are 22 NIDs (or 22 records in total)

- Expected result is (4/22) = 18.18%

 

I hope that helps.

@rax99 Thanks for making it clear. Here are the two measures you are looking for.

 

Test20Calc1 = 
VAR _TotalUniqCount = DISTINCTCOUNT(Test20Measures[Customer])
VAR _SingleCustCount = COUNTROWS(FILTER(SUMMARIZECOLUMNS(Test20Measures[Customer],"Cnt",COUNTROWS(Test20Measures)),[Cnt]=1))
RETURN (_SingleCustCount/_TotalUniqCount)*100
Test20Calc2 = 
VAR _DistinctCount = COUNTROWS(FILTER(Test20Measures,Test20Measures[AgentCount]=1))
VAR _TotalRows = COUNTROWS(Test20Measures)
RETURN (_DistinctCount/_TotalRows)*100

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Thanks, the 2nd calc works fine.

 

However im getting error with calc1:

 

errorPBI.JPG

 

NormalisedDays=TableName

FCRv1 = MeasureName

 

Im not even using AddMissingItems() in the calculation. Any Ideas?

 

Hi @rax99,

Based on my test, you could refer below steps to get the Calc1:

Create a calculated column:

Column = CALCULATE(COUNT(Table1[Customer]),FILTER('Table1','Table1'[Customer]=EARLIER(Table1[Customer])))

1.PNG

Create a measure and you could get the correct result:

Calc1 = CALCULATE(COUNT(Table1[Column]),FILTER('Table1',Table1[Column]=1))/DISTINCTCOUNT(Table1[Customer])

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.