The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi DAX gurus,
I need help writing a measure. The sample data is as shown below:-
I wish to find the percentage of each country within the group "International" every year.
For example, India in year 2020 = 50%; USA in year 2020 = 50%. India in year 2021 = 100%. Etc.
This is what I have written, however, this doesn't work:-
Solved! Go to Solution.
Hi @SachinNandanwar,
Thank you so very much for your response!
This isn't completely the correct response, however, I was able to write it with your help:-
This ?
Country_Percentage_International =
VAR _GroupCount =
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER (
ALLEXCEPT ( 'Table', 'Table'[Year] ),
'Table'[Group] = "International"
)
)
RETURN
DIVIDE (
COUNTROWS (
FILTER (
SUMMARIZE ( 'Table', 'Table'[StudentId], 'Table'[Group] ),
'Table'[Group] = "International"
)
),
_GroupCount,
0
) * 100
this the data
StudentId,Country,Group,Year
1,India,Domestic,2020
2,USA,International,2021
3,Canada,International,2022
4,India,Domestic,2023
5,USA,International,2020
6,Canada,International,2021
7,India,Domestic,2022
8,USA,International,2023
9,Canada,International,2020
10,India,International,2021
11,USA,International,2021
Hi @SachinNandanwar,
Thank you so very much for your response!
This isn't completely the correct response, however, I was able to write it with your help:-
I think every row in your data play role so you just need to devide "one" by calculating the denaminator. you can write a measure as follows:
Measure_share := 1 / calculate (distinctcount(country) , filter (all(your_table) , year=selectedvalue(year) && country(group) = "International")
If this post helps, then I would appreciate a thumbs up 👍 and mark it as the solution to help the other members find it more quickly.
Hi @Selva-Salimi,
I tried your solution, however, it doesn't give the desired output.
Thanks a lot for your attempt though 🙂
So, let me know what was the issue and also what are the visuals you use to display this measure ( image of sample if possible)
This is what it looks like:-
% Test3 is the measure.
Are they the only international countries in 2020? is the column academic_year used in selectedvalue function in measure?!
There are about 100 International countries every year. The years go from 2020 to 2024.
I wrote the measure as per your post:-
User | Count |
---|---|
27 | |
12 | |
8 | |
8 | |
5 |
User | Count |
---|---|
31 | |
15 | |
12 | |
11 | |
7 |