Forum Discussion
Anonymous
3 years agoNot applicable
Using IFs in DAX
Hello. I am new to PBI and I am struggling to get some DAX measures right, and I believe my problem is in understanding the IF function. And maybe using Calculate correctly to filter the informat...
- 3 years ago
Hi Anonymous ,
You can try this method:
Sample data:
New measures:
CONFIRMED REVENUE = VAR _Staff = CALCULATE ( SUM ( 'Fact Staffing forecast'[Revenue DKK] ), FILTER ( 'Fact Staffing forecast', 'Fact Staffing forecast'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] ) ) ) VAR _actual = CALCULATE ( SUM ( 'Fact NAV actual month'[Revenue DKK] ), FILTER ( 'Fact NAV actual month', 'Fact NAV actual month'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] ) ) ) RETURN IF ( SELECTEDVALUE ( 'DimDates'[Post] ) = "Yes", 0, IF ( MAX ( 'DimDates'[Month Number] ) = MONTH ( TODAY () ), _actual + _Staff, _Staff ) )REVENUE TOTAL = VAR _budget = CALCULATE ( SUM ( 'Fact NAV budget'[Revenue DKK] ), FILTER ( 'Fact NAV budget', 'Fact NAV budget'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] ) ) ) RETURN IF ( SELECTEDVALUE ( 'DimDates'[Post] ) = "Yes", _budget, [CONFIRMED REVENUE] )The result is:
Hope this helps you.
Here is my PBIX file.
Best Regards,
Community Support Team _Yinliw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yinliw-msft
3 years agoCommunity Support
Hi Anonymous ,
You can try this method:
Sample data:
New measures:
CONFIRMED REVENUE =
VAR _Staff =
CALCULATE (
SUM ( 'Fact Staffing forecast'[Revenue DKK] ),
FILTER (
'Fact Staffing forecast',
'Fact Staffing forecast'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
)
)
VAR _actual =
CALCULATE (
SUM ( 'Fact NAV actual month'[Revenue DKK] ),
FILTER (
'Fact NAV actual month',
'Fact NAV actual month'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
)
)
RETURN
IF (
SELECTEDVALUE ( 'DimDates'[Post] ) = "Yes",
0,
IF (
MAX ( 'DimDates'[Month Number] ) = MONTH ( TODAY () ),
_actual + _Staff,
_Staff
)
)REVENUE TOTAL =
VAR _budget =
CALCULATE (
SUM ( 'Fact NAV budget'[Revenue DKK] ),
FILTER (
'Fact NAV budget',
'Fact NAV budget'[Date].[Month] = SELECTEDVALUE ( 'DimDates'[Month] )
)
)
RETURN
IF ( SELECTEDVALUE ( 'DimDates'[Post] ) = "Yes", _budget, [CONFIRMED REVENUE] )
The result is:
Hope this helps you.
Here is my PBIX file.
Best Regards,
Community Support Team _Yinliw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.