Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
@hi All,
I have tried to create a logic using set analysis which combines both the sum and aggregation function but failed to get the right method. Here's a simple table to illustrate what I wish to achieve:
I would like to count the number of distinct store ids if the total product sale for the whole month for the given store id is less than a threshold value.
In the example below, the threshold value for product sale is 50.
So if you count the number of STORE ID whose given Product Sale is less than 50 for the whole month, then the result is 1 (Store ID A).
Please note that the table is not complete and contains data for only 4 days.
I've tried this function in a text box but I'm getting errors:
=count( aggr(sum({$<[City] = {'London'}, [Month]={'Jan'}}[Store ID])<50) DISTINCT [Store ID])
Not very sure whether that's the right logic. I would really appreciate your help on this one. Thanks
Store ID | Month | Date | Product Sale | City |
A | Jan | 01/01/2018 | 10 | London |
A | Jan | 02/01/2018 | 5 | London |
A | Jan | 03/01/2018 | 10 | London |
A | Jan | 04/01/2018 | 5 | London |
A | Feb | 01/02/2018 | 96 | London |
A | Feb | 02/02/2018 | 20 | London |
A | Feb | 03/02/2018 | 15 | London |
A | Feb | 04/02/2018 | 30 | London |
B | Jan | 01/01/2018 | 61 | London |
B | Jan | 02/01/2018 | 13 | London |
B | Jan | 03/01/2018 | 25 | London |
B | Jan | 04/01/2018 | 21 | London |
B | Feb | 01/02/2018 | 96 | London |
B | Feb | 02/02/2018 | 20 | London |
B | Feb | 03/02/2018 | 15 | London |
B | Feb | 04/02/2018 | 30 | London |
It does sum up at the store level, but assuming that there is only one city and one month to look at
Hi Sunny - I have just tried the logic and obtain an error in expression. I think it is not recognising the SUM function because of the "= before it. ie The font colour of the sum function is not blue. Is there a way to fix this? Thanks.
Had typos... try this
Count(DISTINCT {<[Store ID] = {"=Sum({<Month = {'Jan'}, City = {'London'}>} [Product Sale]) < 50"}, Month = {'Jan'}, City = {'London'}>}[Store ID])
Works perfectly! Thanks Sunny!
Super
Hi Sunny,
Sorry to bother you again. I have forgotten to add a second condition in that logic. I need to count the number of distinct Store ID if:
(1) the store has sold less than 50 items (Product Sale < 50 ) - Already covered
(2) and has been open for more than 3 days.
I was thinking of adding another condition in the one you posted. Something like max(Date) - min(Date) > 3 for each Store ID. Is it possible to embed such a logic within the one you showed me. If so, where would it be placed?
Many thanks,
RK
May be this
Count(DISTINCT {<[Store ID] = {"=Sum({<Month = {'Jan'}, City = {'London'}>} [Product Sale]) < 50 and max(Date) - min(Date) > 3"}, Month = {'Jan'}, City = {'London'}>}[Store ID])
Will it take account the other months? In this case the min date would be 01/01/2018 and max date would be 04/02/2018. Because you set the month to be Jan in the set analysis, will it take the other months into consideration? Many thanks
It should
In other words, this measure is just to say that a store has been open from 01/01/2018 till the 04/02/2018.