The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi,
I would like to calculate the average value based on distinct values. However, it seems like my filters on page level messes things up:
Filters: Status = Active, Item No: 100||200||300
Contract header | |
No (unique) | Status |
CON001 | Active |
CON002 | Active |
CON003 | Inactive |
CON004 | Active |
Contract invoicing lines
Contract No | Item No | Line Amount |
CON001 | 100 | 10 000 |
CON001 | 101 | 2 000 |
CON002 | 300 | 3 000 |
CON003 | 100 | 4 000 |
CON003 | 101 | 1 000 |
CON004 | 200 | 50 000 |
CON004 | 201 | 20 000 |
Result should be: (10 000 + 3 000 + 50 000) / 3 = 21 000
Also, if I put an additional filter on item no 200 the average should change to 50 000.
Please let me know if something is unclear.
Thanks
Lisa
@LisaB ,
The dax above needs to achieve/compare previous row but there's no row number in your original table, so we need to add an index from 0 or 1 as row number.
For Line Amount you want to achieve is always the first row in each Contract No, so we should also rank the rows in each Contract No using index column.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @v-yuta-msft ,
thank you for the clarification.
I don't think this formula will work for this case since there might be contracts when there is an active contract that does not include any of the ARR items. It might also be an inactive contract that include an ARR item. So only taking the first item (rank =1) will give the incorrect result.
Lisa
Hi,
I have attached an example file showing my report.
I wish to show the average based on the page and report level filters. However, I would the average value to change if filtering by clicking on a bar in the chart.
Hope this clarifies.
Thank you.
Lisa
@LisaB ,
Why does the Item No 101 and 201 not included? Could you please clarify more logic about this?
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @v-yuta-msft,
The value I want to calculate is the average ARR. Items 101 and 201 are not included in the defintion of the ARR. Hope this clarifies.
Thanks.
L
@LisaB ,
Firstly, build a relationship between two tables like below:
Secondly, add an index column in table 'Contract invoicing lines', then create a calculate column using DAX below:
Rank = RANKX(FILTER('Contract invoicing lines', 'Contract invoicing lines'[Contract No] = EARLIER('Contract invoicing lines'[Contract No])), 'Contract invoicing lines'[Index], , ASC, Dense)
Finally, create a slicer based on status column and create a measure in 'Contract invoicing lines' table:
Result = CALCULATE(AVERAGE('Contract invoicing lines'[Line Amount]), FILTER('Contract invoicing lines', 'Contract invoicing lines'[Rank] = 1))
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @v-yuta-msft ,
Thanks. Could you, if possible, please explain the functionality of index and what the rank formula does?
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
80 | |
75 | |
46 | |
39 |
User | Count |
---|---|
135 | |
109 | |
70 | |
64 | |
55 |