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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
kk_shp_user
Helper I
Helper I

Do we need both a Fact_Order and a Fact_Orderlines table in the model?

This is a data modelling question. I have shopify fact_orderline table which is basically a line level fact. I am wondering if I should also have an order level table in my data model.

 

The question arises because, I need to compute the avg. and median days it takes for someone to make a repeat order. My Fact_Orderline table has a 'Days_Since_Previous_Order' field. But the challenge is, this data exists in all the lines of a single order.

 

kk_shp_user_0-1738336309842.png


So, if I do a simple average of that column, I would not get the proper average days it takes to place repeat orders.

 

1. Is there any way, I can compute the average days to reapeat from the Fact_Orderlines table itself? I tried a combination of AVERAGEX + CALCULTE but I could not get the right answer

 

2. Is it always better to have order-level stats like this measure, items in order, totl order value, etc in an order level fact table?

1 ACCEPTED SOLUTION

@kk_shp_user  - Ok, I've fixed up all the issues in this now. Use the DAX below

 

 

VAR _table =
    CALCULATETABLE (
        SUMMARIZE (
            'Table',
            'Table'[ORDERID],
            "@avg", AVERAGE ( 'Table'[DAYS_SINCE_PRV_ORDER] )
        ),
        NOT ISBLANK ( 'Table'[DAYS_SINCE_PRV_ORDER] )
    )
VAR _avg =
    AVERAGEX ( _table, [@avg] )
RETURN
    _avg

 

 

I've attached a file to show this works, the code above is in Measure. If you look at Measure2 I've taken away the filter, in the DAX but added my suggested filter to the table from the column. 

View solution in original post

7 REPLIES 7
mark_endicott
Super User
Super User

@kk_shp_user - You can use AVERAGEX for this:

 

AVERAGEX( VALUES( Table[ORDERID] ), MAX( Table[DAYS_SINCE_PREV_ORDER] ))

 

Please accept as the solution if this works for you, it helps others with the same challenge. 

Thanks! I'll try this. Is there a way to add a filter condition on the table while doing this.

I want to remove the first orders made by customers as they are not repeat orders and will not have the DAYS_SONCE_PREVIOUS_ORDER figure

kk_shp_user_0-1738339121838.png

 

@kk_shp_user 

 

 

IF (
    NOT ( ISBLANK ( Table[DAYS_SINCE_PREV_ORDER] ) ),
    AVERAGEX ( VALUES ( Table[ORDERID] ), MAX ( Table[DAYS_SINCE_PREV_ORDER] ) )
)

 

Or just use the ORDER_SEQ_NO as a filter on the visual through the Filter pane, untick 1. 

 

I'm not able to use columns in NOT(ISBLANK()) mentioned above. It only takes measures as inputs.

I also tried the first measure you mentioned. It gives the maximim values for 'DAYS_SINCE_PREVIOUS_ORDER' inb the table. It does not change even if I filter that column. I filtered it to only consider values less than 50 and it stil shows avg as greater than 2000

kk_shp_user_0-1738345549015.png

 

@kk_shp_user  - Ok, I've fixed up all the issues in this now. Use the DAX below

 

 

VAR _table =
    CALCULATETABLE (
        SUMMARIZE (
            'Table',
            'Table'[ORDERID],
            "@avg", AVERAGE ( 'Table'[DAYS_SINCE_PRV_ORDER] )
        ),
        NOT ISBLANK ( 'Table'[DAYS_SINCE_PRV_ORDER] )
    )
VAR _avg =
    AVERAGEX ( _table, [@avg] )
RETURN
    _avg

 

 

I've attached a file to show this works, the code above is in Measure. If you look at Measure2 I've taken away the filter, in the DAX but added my suggested filter to the table from the column. 

This worked!! Thanks!

Thanks so much! I will confirm this by end of the week!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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