Forum Discussion
Creating Range Buckets using Average per Category ID and Filtering By Date
Hi,
My dataset has ID's with multiple orders. I am trying to calculate average discount across orders per ID.
Avg Discount % = CALCULATE(AVERAGE(Sample[DISCOUNTPERCENT]),Sample,VALUES(Sample[ID]))
And creating a column to bucket the averages of ID's.
Bucket = Switch ( True(),
And( [Avg Discount %]>=-10 ,[Avg Discount %] < Sample[Fixed TMax Var 5%]) , "Green",
And( [Avg Discount %]>=Sample[Fixed TMax Var 5%],[Avg Discount %] < Sample[Fixed TMax Var 15%]) , "Yellow",
And( [Avg Discount %] >= Sample[Fixed TMax Var 15%],[Avg Discount %] < 500), "Red"
)But The result I am getting from the calculate column Bucket is incorrect.
The dataset has 49 ID's, But in the Bucket range, it is showing 46+14 = 60 which is incorrect.
Please help me to achieve the expected result.
4 Replies
- v-yuta-msft
Community Support
Hi anil,
To achieve your requirement, just change your second calculate column to measure.
Avg Discount %Measure = CALCULATE ( AVERAGE ( 'Sample'[DISCOUNTPERCENT] ), ALLEXCEPT ( 'Sample', 'Sample'[ID] ) )The result is as below and the table visual can be filtered by year.
Regards,
Jimmy Tao
- anil
Helper III
Thanks for the reply Jimmy,
If I use this measure, the date slicer will not effect on the measure. It remains constant if we filter by date.
Avg Discount %Measure = CALCULATE ( AVERAGE ( 'Sample'[DISCOUNTPERCENT] ), ALLEXCEPT ( 'Sample', 'Sample'[ID] ) )Which is incorrect. Even if we use date filters it should affect the measure.
- anil
Helper III
Also tried it in a different method. First created a calculated column for Average Discount per ID:
Avg Discount %C = CALCULATE(AVERAGE('Sample'[DISCOUNTPERCENT]),ALLEXCEPT(('Sample'),'Sample'[ID] ))But this calculated column I am unable to filter by dates. When I filter by say Year Month the average values are constant per ID. The filters are not applied to the calculated column.
Help me with the calculation to filter the column by date so I can implement the column to create the bucket.
PBIX File: https://www.dropbox.com/s/8o8jo1676fsb36p/SampleB.pbix?dl=0
- anil
Helper III
Please anyone help me with a solution.