Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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.
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?
Solved! Go to 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.
@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
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 - 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!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 53 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 74 | |
| 69 | |
| 39 | |
| 35 | |
| 23 |