Forum Discussion
Averagex based on dates
Hi.
Can somebody please help me correct this DAX equation? I want to know the average days of inventory based on dates. For visual reasons I have restricted it to 12 months but I want to know the accumulated average days. I am missing something in the DAX because the average days has to be between 400-300 days 🙂
Hope it makes sense.
8 Replies
- johnt75Super User
I would try to examine the data returned by CALCULATETABLE for a particular date to make sure that it is returning what you expect it to. You can use DAX Studio to run the below query
DEFINE VAR DateFilter = TREATAS ( { DATE ( 2022, 6, 30 ) }, 'Kalendar'[Date] ) EVALUATE CALCULATETABLE ( VAR _dato = MAX ( Kalender[Date] ) RETURN CALCULATETABLE ( Data, ALL ( Kalender[Date] ), Data[Registreret dato] < _dato && ( Data[Afsluttet dato] > _dato || ISBLANK ( Data[Afsluttet dato] ) ) ), DateFilter )- AnonymousNot applicable
johnt75
I am not a super user of Power BI, so I dont know the DAX studio. Can I do something else? 😬- johnt75Super User
You could create a temporary table within Power BI
Temp table = VAR DateFilter = TREATAS ( { DATE ( 2022, 6, 30 ) }, 'Kalendar'[Date] ) RETURN CALCULATETABLE ( VAR _dato = MAX ( Kalender[Date] ) RETURN CALCULATETABLE ( Data, ALL ( Kalender[Date] ), Data[Registreret dato] < _dato && ( Data[Afsluttet dato] > _dato || ISBLANK ( Data[Afsluttet dato] ) ) ), DateFilter )You would then be able to examine the table in the data view and see if it contains what you are expecting
- AnonymousNot applicable
johnt75
Hi.
I tested it out and the temp table did show the correct data however where do I go from here? I want to calculate the avarage days.- johnt75Super User
Your formula looks correct to me, the only thing I can think of is that some other filters are in place. When you restricted the visual to just 12 months did you use the Date table or the Data table? You need to use the Date table because that is what the code is removing filters from.
Is it possible to share a PBIX with sample data ?
- AnonymousNot applicable
johnt75
Yes, I have used the calendar date table for visualization. I dont know if it have something do with Data[Registreret dato] and (Data[Afsluttet dato] -> these dates are from my data table but they are connected to the calendar table 😬