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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
Microsoft Employee
Microsoft 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
Microsoft Employee
Microsoft 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
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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