March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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:-
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
18 | |
15 | |
9 | |
7 |
User | Count |
---|---|
37 | |
32 | |
16 | |
16 | |
12 |