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
kulpowerbi
Helper I
Helper I

Comparing one measure output inside another measure is not working with If condition

I have created measure1 it generate output as T or F and I wan to reuse measure1's output inside New_Measure. But it's not working.

 

New_Measure = If ( [measure1]="T", 
CALCULATE(SUM(Sales[SalesAmount]),FILTER('Calendar','Calendar'[Year]=2015)),0)

 

I have draged measure1 in my powerbi canvas which is showing "T" as output then why my New_Measure  is showing Zeros for all the year in a chart.

kulpowerbi_0-1630340383879.png

I guess there is some problem with compareing mesausre output with "T". because if changed the formula to simply String comparision which return true; its working and showign out put for 2015 only. 

 

Measure2=
IF("T"="T", CALCULATE(SUM(Sales[SalesAmount]),FILTER('Calendar','Calendar'[Year]=2015)),0)

 


My Original measures I have combined into one for easy refrence:

M_Sales_dynamic date range for each Bookmark = 
var slider_min = MIN('Calendar'[Date])
var slider_max = max('Calendar'[Date])
var date_min = CALCULATE(MIN('Calendar'[Date]),ALL('Calendar')) 
var date_max = CALCULATE(MAX('Calendar'[Date]),ALL('Calendar')) 
var chk_minmax = IF(and(slider_min=date_min,slider_max=date_max),"T","F")
var bookmark_selection = SELECTEDVALUE(Bookmark[Bookmark])

return
IF(bookmark_selection="1", CALCULATE(Sales[Sales],FILTER('Calendar','Calendar'[QtrYr]="Q4-15")),0)

// IF(AND([M_Bookmark_Selection]="1", [Slider_Min_Max_Date]="T"), CALCULATE(Sales[Sales],FILTER('Calendar','Calendar'[Year]=2015)),
// IF(AND([M_Bookmark_Selection]="2", [Slider_Min_Max_Date]="T"), CALCULATE(Sales[Sales],FILTER('Calendar','Calendar'[Quarter]="Q2")),
// IF(AND([M_Bookmark_Selection]="3", [Slider_Min_Max_Date]="T"), CALCULATE(Sales[Sales],FILTER('Calendar','Calendar'[Month]="May")),
// CALCULATE(Sales[Sales],FILTER('Calendar','Calendar'[WeekdayNum]=1)))))
2 REPLIES 2
amitchandak
Super User
Super User

@kulpowerbi , Try like

 

New_Measure = If ( [measure1]="T", 
CALCULATE(SUM(Sales[SalesAmount]),FILTER('Calendar','Calendar'[Year]=2015)),blank() )

Hi @amitchandak  thanks for helping on this. I tried the measure you provided, but it's returning completly blank visaul.  

here is my PBI file, if you can help will really appricate this.

Background: I have used radio button with static table and a single column where values are stored as 1,2,3,4 .. and used bookmark to select different values in single selection slider(radio button) and used measure like this: SELECTEDVALUE(Bookmark[Bookmark])
so it tells me which bookmark is selected and based on bookmark selected I would use differnt Years or month in each hirachy in the axis.

My bookamrks  is doing Drill down for Date(Year, QTR, MONTH)

and i wan to filter default year(2015), month ="Jan", "mar", QTR="QT" only.. in my visual while opening first time.

 

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.