cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
NorthernKarsten
Helper I
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:
NorthernKarsten_0-1620039361321.png

 

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
daxer-almighty
Solution Sage
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

View solution in original post

4 REPLIES 4
daxer-almighty
Solution Sage
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

View solution in original post

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

NorthernKarsten_0-1620113595375.png


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

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.

amitchandak
Super User IV
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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors