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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Add missing year(categorical column) and assign zero value to count for each medicine category

My sample dataset as follows:

YearMedicineCount
2018M11
2019M11
2020M11
2018M21
2019M21
2018M31


I need output as follows:

YearMedicineCount
2018M11
2019M11
2020M11
2018M21
2019M21
2020M20
2018M31
2019M30
2020M30

 

I want to have all the values in the Year column for each medicine and assign value 0 to the counts for missing year. The year column will have more years moving forward - starting from 2018 and then every year, a new year category will be added. For example: It's 2022 now, so years in my dataset are from 2018 till 2022, but will have 2023, 2024.... every year.
Any help would be highly appreciated! Thanks!

1 ACCEPTED SOLUTION
bcdobbs
Community Champion
Community Champion

Hi,

 

I imported your data and called it Table1 (normally give it a descriptive name!).

I then created two calculated tables:

Medicine = DISTINCT ( Table1[Medicine] )
Year = DISTINCT ( Table1[Year] )

 

Then created relationships:

bcdobbs_0-1644598188991.png

 

Then in Table1 added a measure:

# Medicines = SUM ( Table1[Count] ) + 0

The +0 stops it returning blank.

 

You can then use them in a table visual with Medicine and Year coming from your new dimension tables:

 

bcdobbs_1-1644598289396.png

 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

2 REPLIES 2
bcdobbs
Community Champion
Community Champion

Hi,

 

I imported your data and called it Table1 (normally give it a descriptive name!).

I then created two calculated tables:

Medicine = DISTINCT ( Table1[Medicine] )
Year = DISTINCT ( Table1[Year] )

 

Then created relationships:

bcdobbs_0-1644598188991.png

 

Then in Table1 added a measure:

# Medicines = SUM ( Table1[Count] ) + 0

The +0 stops it returning blank.

 

You can then use them in a table visual with Medicine and Year coming from your new dimension tables:

 

bcdobbs_1-1644598289396.png

 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Anonymous
Not applicable

Awesome! You're the best!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors