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
awitt
Helper III
Helper III

Conditional Measure Based on Date

I have a set of data that has one record per OrderItemId which is a specific unit of a sale. I have two columns, CONDATE which is the begging date of this sale and FINALDATE which is when the sale closed in some way. I also have a separate date table.

 

What I want is to do is have a date field that a user enters and a measure returns how many OrderItemIDs were "active" for that specific date. 

 

For example - if the date selected by the user was 1/3/2020, the result would be 2 since orders 1234001 & 1234002 had been ordered but not yet finalized. If the date was 1/5/2020 then the result would be 4. If the date was 1/8/2020 the result would be 3 since OrderItemID 1234003 had hit a FINALDATE of 1/6, so this order would be excluded. 

 

OrderItemIDCONDATEFINALDATE

1234001

1/1/20201/30/2020
12340021/1/20201/30/2020
12340031/4/20201/6/2020
12340041/4/20201/30/2020
12340051/9/20201/30/2020
12340061/9/20201/30/2020

 

 

1 ACCEPTED SOLUTION

Hi @awitt ,

 

We can try to use the following measure to meet your requirement:

 

Count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[OrderItemID] ),
    FILTER (
        'Table',
        OR (
            ISBLANK ( 'Table'[FINALDATE] ),
            NOT (
                OR (
                    'Table'[CONDATE] > MAX ( 'DateSlicer'[Date] ),
                    'Table'[FINALDATE] <= MIN ( 'DateSlicer'[Date] )
                )
            )
        )
    )
)


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-lid-msft
Community Support
Community Support

Hi @awitt ,

 

We can create a calculated table and a measure to meet your requirement:

 

Calculated table:

 

DateSlicer = CALENDAR(DATE(2019,1,1),DATE(2021,12,31))

 

Measure:

 

Count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[OrderItemID] ),
    FILTER (
        'Table',
        NOT (
            OR (
                'Table'[CONDATE] > MAX ( 'DateSlicer'[Date] ),
                'Table'[FINALDATE] <= MIN ( 'DateSlicer'[Date] )
            )
        )
    )
)

 

2.jpg3.jpg


By the way, PBIX file as attached.


Best regards,



Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-lid-msft I'm pretty sure this is going to work for my dataset. The hard thing is proving the results. Is there a way to have a table that only returns the results of a given day as well?

 

For instance, I have some days where the result for that day is over 20,000. I know i'm going to be asked which 20,000 records made up that number but I haven't been able to do that yet. Thoughts?

Hi @awitt ,

 

We can put the measure into visual filter of table chart, then set it "is not blank" or "is not zero" to meet your requirement:

 

3.jpg4.jpg


By the way, PBIX file as attached.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-lid-msft The only thing that seems off is that Blank FINALDATE values are not included in the measure and they should be. If this is essentially open orders, there wont be Final Dates for active orders that haven't yet been completed. 

Hi @awitt ,

 

How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?


Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @awitt ,

 

We can try to use the following measure to meet your requirement:

 

Count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[OrderItemID] ),
    FILTER (
        'Table',
        OR (
            ISBLANK ( 'Table'[FINALDATE] ),
            NOT (
                OR (
                    'Table'[CONDATE] > MAX ( 'DateSlicer'[Date] ),
                    'Table'[FINALDATE] <= MIN ( 'DateSlicer'[Date] )
                )
            )
        )
    )
)


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

You will need something like Open Tickets: https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/td-p/409364


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.