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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
littlemojopuppy
Community Champion
Community Champion

C# Scripts to Create Measures

Hi!

 

A couple weeks ago I asked for some advice/help on writing a C# script to create measures based on the calculation items in a data model.  I wanted to share what I came up.

 

There are three files in the zip file:

  • A DAX script to create calculation items for different time periods (MTD, QTD, YTD, etc.)
  • A DAX script to create calculation items for comparing time periods (MTD vs. prior MTD, etc.)
  • A C# script to create measures

They can all be executed in Tabular Editor 3 (not sure about TE2...haven't tried it).  Execute the two DAX scripts to create those calculation items.  Then execute the C# script.  It will loop through each of the measures in your model and create a measure based on each of the calculation items.  It'll also add formatting and a basic description.

 

A huge shout out to @parry2k for pointing me in the right direction to get started with this!

1 ACCEPTED SOLUTION
littlemojopuppy
Community Champion
Community Champion

@v-luwang-msft will do!

 

@parry2k: again, thank you for pointing me in the right direction!  🙂

View solution in original post

4 REPLIES 4
littlemojopuppy
Community Champion
Community Champion

@v-luwang-msft will do!

 

@parry2k: again, thank you for pointing me in the right direction!  🙂

v-luwang-msft
Community Support
Community Support

Hi @littlemojopuppy ,

Thank you for sharing.it is helpful. You can reply in your own post after and flag it as an answer. This will help more people, many users, who will only view solved cases.

 

 

Best Regards,
Lucien

@v-luwang-msft @Do you think this would be better served as a blog post?  And not a solution?  I didn't actually ask for help with this...

HI  @littlemojopuppy ,

The forum also often appears to share the post, this does not harm the elegance. Of course, if you're going to blog, you might want to go into more detail.
 
Best Regards
Lucien

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors