Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jessicarocha
Helper IV
Helper IV

Count distinct of a text column that changes according to the filter/rows

I have a table in this structure:

Material ID Fiscal Year
89809807 2017/18
56987098 2017/18
89809807 2017/18
34678907 2018/19
56987098 2018/19
56987098 2018/19
11111357 2018/19

 

I would like to create a card or a table that shows the total number of different products. It should be possible to filter per fiscal year. So, this is what I would like to have: 

Fiscal Year Number of different materials
2017/18 2
2018/19 3


Instead, I am getting how many distinct materials there are in total, without considering the year at all. I get this: 

 

Fiscal Year Number of different materials
2017/18 4
2018/19 4


I tried to create a quick measure. I tried to use the "count distinct" option of when you put a variable in the table. I also tried to calculate some measures but the result is always the same. 

 

Additional info: both columns are text data type

This is a fact table. So there is a relation of 1 to many with Date table, for example. 

Example of a created measure:

SUMX (
VALUES ( 'Dim Fiscal Year'[Fiscal Year]),
CALCULATE ( DISTINCTCOUNT ( 'Fact v06'[IDNR] ) )
)


Do you have any idea where my problem could be? 
Thanks in advance!

Dummy example file:
Dummy PowerBI  

I am unable to upload the file here. Therefore, it is in google drive.
The data source is a folder. Two excel files are combined.

1 ACCEPTED SOLUTION
moizsherwani
Continued Contributor
Continued Contributor

See if the below helps

 

Relationship Deactivated (getting the same result as you)

 

moizsherwani_1-1632088520713.png

 

moizsherwani_0-1632088468906.png

 

Relationship Activated (please note you must use the Fiscal year from the Dim table and not the Fact table)

moizsherwani_2-1632088563147.png

 

moizsherwani_3-1632088585153.png

 

Also I used the same measure as you did

 

moizsherwani_0-1632088835260.png

 

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

View solution in original post

12 REPLIES 12
moizsherwani
Continued Contributor
Continued Contributor

See if the below helps

 

Relationship Deactivated (getting the same result as you)

 

moizsherwani_1-1632088520713.png

 

moizsherwani_0-1632088468906.png

 

Relationship Activated (please note you must use the Fiscal year from the Dim table and not the Fact table)

moizsherwani_2-1632088563147.png

 

moizsherwani_3-1632088585153.png

 

Also I used the same measure as you did

 

moizsherwani_0-1632088835260.png

 

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Hi @moizsherwani . thanks for the help! 
i activated the relationship again, just like you did, to see if this was really the problem. but I still get the same weird result...

jessicarocha_2-1632116429416.pngjessicarocha_3-1632116443051.png

 

1) Check to ensure the relationship between the date and fact table is on the correct field

 

2) Pull the date and ID from the Fact DNK6 Table into a visual and see what comes up (don't use the fiscal year table). If it still shows duplicates it might be that your Fact DNK6 Table has either some

duplicate data (or some erroneous data).

 

If that doesn't work I would also suggest sending the pbix with sample data for a view.

 

Regards,

 

Moiz

 

If this post helps, please Accept it as Solution to help other members find it.

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Hi @moizsherwani 

 

I still can't find the error. So I created a sample data and pbix to see if you can help me. 
Thank a lot for the effort, I really appreciate it!

Unfortunatelly I can not add the files here. It says that the option is not supported for me. Maybe because I am a new member?! So, I added in a google drive folder, I hope it is ok. Here is the link to access: 
Dummy PowerBI 

Info: The source of the data is a folder. The excel files are combined.

Kind regards, 

Jéssica

I downloaded your dummy file. Just looking at it by eye in the data I see 6 distinct IDNR for each fiscal year (excluding duplicates) which is what is showing on the visuals. What is the count you are expecting?

 

moizsherwani_0-1632127797453.png

 

moizsherwani_1-1632127861180.png

 

moizsherwani_2-1632127960905.png

 

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

@moizsherwani you are totally right. I just realised now that I was missing one filter. I am so sorry for all the trouble. Thanks again for the help! It was very useful! 

jessicarocha_0-1632128324372.png

 

StefanoGrimaldi
Resident Rockstar
Resident Rockstar

caus you have the relantionship inactive, isnt a active relantionship, looks like you have some issue on the relantionship of the model send a full pic of all the relationship, or send the pbix with dummy data





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




hi @StefanoGrimaldi 

thanks for the explanation. I thought that was the same thing. I cleaned the model a bit and activated everything again. still have the same problem. Here are the pics as requested: 

jessicarocha_0-1632116265250.pngjessicarocha_1-1632116289708.png

 

@StefanoGrimaldi 

I created a dummy example so you can understand better my problem. I really appreciate the effort in trying to help me. Thanks a lot, really!

I am unable to upload files here. So I created a folder in Google Drive. I hope it works. 

Dummy PowerBI 

PS: The data source is a folder. It combines the excel files.

StefanoGrimaldi
Resident Rockstar
Resident Rockstar

I would recommend you to post the pbix with dummy data, cause there could be a number of possible issue that its generating this problem, a quick look at the result vs how you say it should appears look like a relantionship problem between fact table and the date table, or the fields from each you using to arm the visual, you dont need dax also for this, you can do this with a simple table visual and setting de materiales to count distint on the field section of the visual,

again, share a dummy data pbix to get a pinpoint solution for your problem, or add screemshot of how you have everything set up 





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




@StefanoGrimaldi I am so sorry for all the trouble. It was my fault. I was missing one filter. That is why the count was weird. Thanks again for the help!

Hi @StefanoGrimaldi 

Thank you for answering me.
I don't think the problem is in the relationship. I deactivated everything and I am using the data of a single table. Still, the result is weird when I use the count distinct.

jessicarocha_0-1632078715718.pngjessicarocha_1-1632078765958.pngjessicarocha_2-1632078792812.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.