cancel
Showing results for
Did you mean:
Helper I

Third condition in IF measure based on a date

Hi.
I have a matrix with the purpose to show what we have sold or not sold to a customer based on this measure:

Sold/Not Sold =
(IF(SUM('Salestable1'[Sales Quantity])>0,UNICHAR(9989),UNICHAR(10060)))
The matrix looks like this:

My question:
I want to add a third condition to my measure that shows that if Sales Quantity >0 after 01.05.2021 and Sales Quantity<=0 before 01.05.2021 then a "🌟" should appear.
Can someone help me to show me an example of how this could be done in my measure?
Thanks!
1 ACCEPTED SOLUTION
Solution Sage
``````[Total Quantity] = SUM( 'Salestable1'[Sales Quantity] )

[Sold/Not Sold] =
var CutofffDate = DATE( 2021, 5, 1)
var TotalQuantityBeforeIsNotPositive =
CALCULATE(
[Total Quantity] <= 0,
// 'Calendar' must be a proper date table
// in the model connected to the fact table.
'Calendar'[Date] < CutoffDate
)
var TotalQuantityAfterOrOnIsPositive =
CALCULATE(
[Total Quantity] > 0,
// 'Calendar' must be a proper date table
// in the model connected to the fact table.
'Calendar'[Date] >= CutoffDate
)
var TotalQuantityWeirdnessCondition =
TotalQuantityBeforeIsNotPositive
&&
TotalQuantityAfterOrOnIsPositive
var Result =
switch( true(),

TotalQuantityWeirdnessCondition,
"<glowing star>",

[Total Quantity] > 0,
UNICHAR(9989),

// When [Total Quantity] <= 0...
UNICHAR(10060)
)
return
Result``````
4 REPLIES 4
Solution Sage
``````[Total Quantity] = SUM( 'Salestable1'[Sales Quantity] )

[Sold/Not Sold] =
var CutofffDate = DATE( 2021, 5, 1)
var TotalQuantityBeforeIsNotPositive =
CALCULATE(
[Total Quantity] <= 0,
// 'Calendar' must be a proper date table
// in the model connected to the fact table.
'Calendar'[Date] < CutoffDate
)
var TotalQuantityAfterOrOnIsPositive =
CALCULATE(
[Total Quantity] > 0,
// 'Calendar' must be a proper date table
// in the model connected to the fact table.
'Calendar'[Date] >= CutoffDate
)
var TotalQuantityWeirdnessCondition =
TotalQuantityBeforeIsNotPositive
&&
TotalQuantityAfterOrOnIsPositive
var Result =
switch( true(),

TotalQuantityWeirdnessCondition,
"<glowing star>",

[Total Quantity] > 0,
UNICHAR(9989),

// When [Total Quantity] <= 0...
UNICHAR(10060)
)
return
Result``````
Helper I

@daxer-almighty that seems to work great!
It seems like I cant sort it by the three conditions in my matrix:

Do you have a solution for this aswell?
And: is it possible to get those three conditions in a slicer visual?
Appreciate it!

Solution Sage

Of course, it is possible. But what do you mean by "can't sort them"? The <glowing star> is something I put in but you have to change it to the right unicode character. Then, to sort them the way you want you have to use a trick called "zero-character space" and attach 0, 1 and 2 such spaces to the beginning of each of these unicode chars. Google for an article on sorting measure values on www.sqlbi.com or find the relevant vid on YT by Alberto Ferrari where he shows how to do it.

To get these chars in a slicer you have to create a disconnected table with these chars (plus the spaces) as values. It'll be a disconnected dimension.

Super User IV

@NorthernKarsten , if date is in context of the visual then try like (correct the unicode)

Switch(true() ,
SUM('Salestable1'[Sales Quantity])>0 && Max(Date[Date]) >= date(2021,05,01),UNICHAR(9989),
SUM('Salestable1'[Sales Quantity])>0 && Max(Date[Date]) < date(2021,05,01),UNICHAR(10060),
,UNICHAR(10060))

If not they you have create measure for before and after 1st may

Proud to be a Super User!

Announcements