Hello All,
I have a sample data of sales which has applications, their categories and sales.
I need to calculate the distinct count of applications which has sales as zero or blank.
Below is the sample data for power query.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZVRa4MwFIX/ysXnDnSFMR+v1m7dVidm7TZKkZBaF6oGkshgv34O1tFq7Szx0XNyvpsTQlytrOspwpJLXdEcSEGlBp/KjTWyYpGnCgquFC8z4CXIWrhiVNNcZLVvW+vRyhq/34FH2U5st5ylv7GYq536W3I7AZz1BuL4xnXs+hMZE1WpVbeTfIokxrY/F3Fb/JmO9eisLNKT1PbGj6wu+f9Crms7zslCTadZaO8fFdqLnYUOFzQKHVpdcv9CBKOkMQABC/olSlim5UZI8OutSZonuOiP72J4sTnDR3PGJDBnBMScMR3gPGYv5oyHyJwxfzNnhE/mjGgABhngfiweB2CQM0/L2VD/wVGI4D0T//6SlIevBII4gjDVquI6vSgsFPsArLSAqP5bqX7Z9Tc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Application = _t, Category = _t, Sales = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Application", type text}, {"Category", type text}, {"Sales", Int64.Type}})
in
#"Changed Type"
In power bi, if we dont select any value from slicer, it considers as ALL ARE SELECTED.
Problem here is there is only one application which has 0 sales for ALL the categories.
But when i do distinctcount of Application column it gives me 22 as count.
Because, here, I believe the OR condition is been applied and hence it is giving 22 as distinct applications count.
But in my case, it should be AND, should give the distinctcount as 1 as there is only one application with all the categories as blank.
If i filter on any other category, then based on the category selection it should give the distinctcount of applications which has 0 sales. and it works fine by default.
But the problem is with when we dont select anything from category, and the OR condition is been applied by default, which results in wrong distinctcount.
Can anyone please help on this.
Thanks,
Mohan V.
Solved! Go to Solution.
Hi @MohanVanks
If you add "Application" column to the card visual and select Count (Distinct) aggregation for it, the "OR condition" behavior you observed is correct. This is by design.
To achieve your expected result like "AND" behavior, you need to create a measure to count. You can try the following measure:
Distinct Count of Application =
var __table = SUMMARIZE('Table','Table'[Application],"countOfCategory",DISTINCTCOUNT('Table'[Category]))
var __categoryCount = DISTINCTCOUNT('Table'[Category])
RETURN
COUNTROWS(FILTER(__table,[countOfCategory]=__categoryCount))
I have attached the sample file at bottom. Hope it helps.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Hi @MohanVanks
If you add "Application" column to the card visual and select Count (Distinct) aggregation for it, the "OR condition" behavior you observed is correct. This is by design.
To achieve your expected result like "AND" behavior, you need to create a measure to count. You can try the following measure:
Distinct Count of Application =
var __table = SUMMARIZE('Table','Table'[Application],"countOfCategory",DISTINCTCOUNT('Table'[Category]))
var __categoryCount = DISTINCTCOUNT('Table'[Category])
RETURN
COUNTROWS(FILTER(__table,[countOfCategory]=__categoryCount))
I have attached the sample file at bottom. Hope it helps.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
User | Count |
---|---|
211 | |
82 | |
81 | |
78 | |
46 |
User | Count |
---|---|
167 | |
86 | |
81 | |
79 | |
74 |