Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Maciej1992
New Member

Counting orders based on their latest status

Hello,

For some time now I am strugling with measure that will count orders based on their last status.

I tackled this from multiple angles and even ask ChatGPT for help, but couldn't find a solution.

 

My goal is table visualization with columns for:

names of statuses in first column (STATUS_DICTIONARY[NAME]),

number of orders which have given status as their latest,

% of GT

 

My model looks like this:

Maciej1992_0-1695725679218.png

 

ORDERS[ID] - 1 to * - ORDERS_STATUS[ID_ORDER]

STATUS_DICTIONARY[ID] - 1 to * - ORDERS_STATUS[ID_STATUS]

 

 

And below is some sample data:

 

ORDERS

IDNUMBER
123/01/1
223/01/2
323/01/3
423/01/4
523/01/5

 

 

ORDERS_STATUS

IDID_ORDERID_STATUSDATE_CHANGE
11126.09.2023
21226.09.2023
32126.09.2023
43127.09.2023
54127.09.2023
61327.09.2023
72528.09.2023
83228.09.2023
93329.09.2023
105130.09.2023
114230.09.2023

 

STATUS_DICTIONARY

IDNAME
1aaa
2bbb
3ccc
4ddd
5eee

 

 

 

Based on all above I expect result to look like this:

 

STATUS NAMENUMBER OF ORDERS% OF GT
aaa120%
bbb120%
ccc240%
ddd00%
eee120%

 

 

I will be very gratefull for any help.

Thank you!

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

@Maciej1992 , here are the measures:

orders_amt = 
VAR t =
    FILTER (
        ORDERS_STATUS,
        VAR order_id = CALCULATE ( SELECTEDVALUE ( ORDERS[ID] ) )
        VAR maxDt =
            CALCULATE (
                MAX ( ORDERS_STATUS[DATE_CHANGE] ),
                ORDERS_STATUS[ID_ORDER] = order_id,
                ALL ( ORDERS_STATUS )
            )
        VAR maxStatus =
            CALCULATE (
                MAX ( ORDERS_STATUS[ID_STATUS] ),
                ORDERS_STATUS[DATE_CHANGE] = maxDt,
                ORDERS_STATUS[ID_ORDER] = order_id
            )
        RETURN
            ORDERS_STATUS[ID_ORDER] = order_id && ORDERS_STATUS[ID_STATUS] = maxStatus
    )
RETURN
    COUNTROWS ( t )
% OF GT = 
VAR latestRows = [orders_amt]
VAR allrows =
    CALCULATE (
        SUMX ( VALUES ( STATUS_DICTIONARY[NAME] ), [orders_amt] ),
        ALL ( STATUS_DICTIONARY[NAME] )
    )
RETURN
    latestRows / allrows

ERD_0-1695831749025.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

2 REPLIES 2
ERD
Community Champion
Community Champion

@Maciej1992 , here are the measures:

orders_amt = 
VAR t =
    FILTER (
        ORDERS_STATUS,
        VAR order_id = CALCULATE ( SELECTEDVALUE ( ORDERS[ID] ) )
        VAR maxDt =
            CALCULATE (
                MAX ( ORDERS_STATUS[DATE_CHANGE] ),
                ORDERS_STATUS[ID_ORDER] = order_id,
                ALL ( ORDERS_STATUS )
            )
        VAR maxStatus =
            CALCULATE (
                MAX ( ORDERS_STATUS[ID_STATUS] ),
                ORDERS_STATUS[DATE_CHANGE] = maxDt,
                ORDERS_STATUS[ID_ORDER] = order_id
            )
        RETURN
            ORDERS_STATUS[ID_ORDER] = order_id && ORDERS_STATUS[ID_STATUS] = maxStatus
    )
RETURN
    COUNTROWS ( t )
% OF GT = 
VAR latestRows = [orders_amt]
VAR allrows =
    CALCULATE (
        SUMX ( VALUES ( STATUS_DICTIONARY[NAME] ), [orders_amt] ),
        ALL ( STATUS_DICTIONARY[NAME] )
    )
RETURN
    latestRows / allrows

ERD_0-1695831749025.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Worked like a charm! Thank you very much. You truly are a Rockstar 🙂

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.