This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowThe Fabric community is upgrading! Read all of the details including the timeline and what you can expect. Learn more
Dear all,
I'm trying to calculate the MAA (Moving Annual Average) value - but I would need your help on this KPI & DAX language.
Data are like this:
-> Conformity level (Grade A = OK/NON OK per scan/factory/etc.).
So I would need to calculate the average of grade A on the last 13 periods.
| year | CONFORMITY | Period | Factories |
| 2020 | OK | P13 | RCA |
| 2020 | OK | P13 | RCA |
| 2020 | OK | P13 | RCA |
| 2021 | OK | P01 | RFT |
| 2021 | WRNG_NOK | P01 | RFT |
| 2021 | OK | P02 | RNI |
| 2021 | OK | P02 | RNI |
| 2021 | OK | P02 | RNI |
| 2021 | OK | P02 | RNI |
| 2021 | OK | P02 | RNI |
% Grade A from the last 13 periods -> Total Count OK/(Conform + WRNG + NON OK)*100 from the last 13 periods
Above is an exemple (the 13 periods are missing) -> expected results = 90 %
Thanks for your help
Hervé
Hi @Anonymous ,
The basis for processing the same ranking, skip stands for sparse ranking, and the next ranking is equal to the number of all previous rankings + 1; dense stands for dense ranking, which only accumulates the ranking, regardless of the number. Use skip by default. ASC stands for ascending order, DESC is used by default.
I did a test, it can be used as a reference:
M1 = RANKX('Table',[Value],,ASC,Dense)M2 = RANKX('Table',[Value],,ASC,Skip)
For specific formulas, please refer to the blog link provided by me:RANKX – DAX Guide
Best Regards,
Henry
If this post also helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello
If you take my example above, what do you mean by "value"?
Thanks
Hervé
Hi @Anonymous ,
The "value" field is the column I need to sort.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello,
And more baiscally can I use this formula:
Hi @Anonymous ,
Yes, your formula is also a good way. If the problem has been solved or my reply provided you with help, you can mark it as the correct answer to to help the other members find it more quickly.😊
Best Regards,
Henry
@Anonymous , First create a separate year period table with period rank column and join both on yearperiod combine column
Period Rank = RANKX(all('Period'),'Period'[year period],,ASC,Dense)
Then you can measure like
This Period = CALCULATE([% Grade A ], FILTER(ALL('Period'),'Period'[Period Rank]=max('Period'[Period Rank])))
Last Period = CALCULATE([% Grade A ], FILTER(ALL('Period'),'Period'[Period Rank]=max('Period'[Period Rank])-1))
Last 13 Period = CALCULATE([% Grade A ], FILTER(ALL('Period'),'Period'[Period Rank]>=max('Period'[Period Rank])-13 && 'Period'[Period Rank]<=max('Period'[Period Rank])))
Hello,
What does it mean -> ASC,Dense?
Thanks
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
| User | Count |
|---|---|
| 23 | |
| 22 | |
| 14 | |
| 14 | |
| 13 |
| User | Count |
|---|---|
| 45 | |
| 38 | |
| 24 | |
| 22 | |
| 20 |