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
joshua1990
Post Prodigy
Post Prodigy

COUNT order below specific state and no records between changes

Hello!

I have a transaction table that shows me the order, state and the date when a state was changed:

Order NumberStateValueDate Changed
999815001.07.2021
999825005.07.2021
999835008.07.2021
999915005.07.2021
999925006.07.2021

 

This table is linked by a date table.

Now I would like to count the number of order for each date where the state is below 3.

As you can see there are no records between some day since the state was not changed.

 

How can this be calculated in dax?

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @joshua1990 
Here is a sample file with the solution https://we.tl/t-FABvxI5sFa

# Of Orders (Status < 3) = 
SUMX ( 
    'Table',
    VAR CurrentDate = VALUES ( 'Date'[Date] )
    VAR CurrentState = 
        'Table'[State]
    VAR StartDate = 
        'Table'[Date Changed]
    VAR NextDate = 
        CALCULATE ( MAX ( 'Table'[Date Changed] ), 'Table'[State] = CurrentState + 1, ALLEXCEPT ( 'Table', 'Table'[Order Number] ) )
    VAR EndDate = 
        IF ( ISBLANK ( NextDate ), StartDate, NextDate - 1 )
    VAR CurrentStatusDates =
        CALENDAR ( StartDate, EndDate )
    VAR Result =
        COUNTROWS ( INTERSECT ( CurrentStatusDates, CurrentDate ) )
    RETURN
        IF ( Result > 0 && CurrentState < 3, 1 )
)

1.png

View solution in original post

6 REPLIES 6
tamerj1
Super User
Super User

Hi @joshua1990 
Here is a sample file with the solution https://we.tl/t-FABvxI5sFa

# Of Orders (Status < 3) = 
SUMX ( 
    'Table',
    VAR CurrentDate = VALUES ( 'Date'[Date] )
    VAR CurrentState = 
        'Table'[State]
    VAR StartDate = 
        'Table'[Date Changed]
    VAR NextDate = 
        CALCULATE ( MAX ( 'Table'[Date Changed] ), 'Table'[State] = CurrentState + 1, ALLEXCEPT ( 'Table', 'Table'[Order Number] ) )
    VAR EndDate = 
        IF ( ISBLANK ( NextDate ), StartDate, NextDate - 1 )
    VAR CurrentStatusDates =
        CALENDAR ( StartDate, EndDate )
    VAR Result =
        COUNTROWS ( INTERSECT ( CurrentStatusDates, CurrentDate ) )
    RETURN
        IF ( Result > 0 && CurrentState < 3, 1 )
)

1.png

Whitewater100
Solution Sage
Solution Sage

Hi:

You can use something like

Count of State < 3 = 

COUNTROWS(FILTER(Table, Table[State] < 3))
 
You would sub in your table name where I have table. I hope this helps..

@Whitewater100 : This will not work. For instance 07.01.2022 I will get now value, right? Because there is no record for 07.01.2022. But order 9998 still has a state below 3, right?

Hi:

Try thiscalculated column and then a measure. I hope this solves your question..

Calc Col 

Count of State < 3 =
IF('Table'[State] <3,1,BLANK())
Measure
No. Orders ❤️ =
SUM('Table'[Count of State < 3])
Whitewater100_0-1651447485898.pngWhitewater100_1-1651447552400.png

 

Hi:

I don't know how the heart snuck in there! 

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.

Top Solution Authors