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

Visualize data based on results of if then

Greetings,

 

I'm trying to visualize data based on the results of an if then statement.  

 

CalculateTerm =IF(DISTINCTCOUNT('Player Query'[Years_Played])>3,"LongTerm","ShortTerm")

 

I'd like to graph the results in a way where count of longterm and count of short term are compared.  can't seem to wrap my head around how to accomplish this.

1 ACCEPTED SOLUTION

@Phil_Seamark

 

I finally got it!  The formula you provided was very close.  

 

Short Term = CALCULATE(
DISTINCTCOUNT('Player Query'[ID]),FILTER(VALUES('Player Query'[ID]),[Years Played]<=3))

 

I'm still a bit unclear as to how the VALUES function works or why it was necessary for that matter.  Thanks for your direction!

View solution in original post

8 REPLIES 8
Phil_Seamark
Employee
Employee

Hi @KUNGFUPANDA559

 

Would the following two calculated measures help

 

Long Term = CALCULATE(DISTINCTCOUNT('Player Query'[Column1]),(FILTER('Player Query','Player Query'[Years Played]>3)))
Short Term = CALCULATE(DISTINCTCOUNT('Player Query'[Column1]),(FILTER('Player Query','Player Query'[Years Played]<=3)))

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

@Phil_Seamark

 

I finally got it!  The formula you provided was very close.  

 

Short Term = CALCULATE(
DISTINCTCOUNT('Player Query'[ID]),FILTER(VALUES('Player Query'[ID]),[Years Played]<=3))

 

I'm still a bit unclear as to how the VALUES function works or why it was necessary for that matter.  Thanks for your direction!

@Phil_Seamark

 

When i export the data, i find that there are 957 rows that are "Long Term".  However, when using the Long Term expression you've provided, when i add it to a table it only displays 28 values.  It does not appear to be calculating correctly.

Hi @KUNGFUPANDA559

 

These calculated measures are doing a DISTINCTCOUNT.  Could it be there are 28 unique values in your 957 rows?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

@Phil_Seamark

 

I believe there must be something overall with the way i have things configured.

 

 

 The measure works as desired when creating a table and listing ID>GamesPlayed > Term.  FWIW

 

Term := if ( games played >3,"Long Term", Short Term") 

 

where

 

"Games Played" := distinctcount('Player Query' [days played])

Phil_Seamark
Employee
Employee

Hi @KUNGFUPANDA559

 

You might be close with it.  Have you tried dragging that measure to both the axis AND the values area of a chart such as a Bar Chart?

 

The values area will give you a count.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

@Phil_Seamark I'm unable to place the values in the axis or values field and i dont have the slightest idea why!

Hi  @KUNGFUPANDA559

 

It was me being lazy.  I will look at this later tonight when I have the chance to mock up some data. 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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.