Forum Discussion
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!
4 Replies
- v-luwang-msftCommunity 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- littlemojopuppyCommunity Champion
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...
- v-luwang-msftCommunity Support
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 RegardsLucien
- littlemojopuppyCommunity Champion