Forum Discussion
Creating Measures in Tabular Editor With C Sharp Scripts
Hi. I have a problem and I could use some help.
I have a consulting firm that was charged with creating enterprise tabular models for big things like sales, inventory, etc. They delivered models, but the measures in them need a lot of help. For example, the sales model has approximately 2400 measures. there is one base measure for "sales", "cost", etc. and then about 25 "time intelligence" calculations for MTD, QTD, YTD as well as compared to prior month, year, percent change from another period, etc. On reviewing these measures, about 40% of them are wrong: they don't calculate correctly. The money has run out, so they're not fixing anything anymore. 😖
I've written calculation groups/items to actually use real time intelligence for each. I've verified that measures using these calculation group/items are correct. But I have the problem of how to actually create/update measures in the data model itself because unfortunately I don't have the skill set to code in C sharp. And I'm not correcting 2400 measures manually.
What I'm hoping someone can provide is (in order of preference):
- Sample code to loop through a list of base measures and create the necessary time intelligence measures
- Resources to educate a C sharp programmer on how this can be done
- Any other assistance!
- Resources on how I can quickly learn enough C sharp to do this myself 😕
Would appreciate any help that anyone could provide.
littlemojopuppy I'm sure this will get you going. GitHub - TabularEditor/Scripts: Community repository for sharing and discussing scripts for use with Tabular Editor
✨ Follow us on LinkedIn and to our YouTube channel
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.
7 Replies
- parry2kSuper User
littlemojopuppy I'm sure this will get you going. GitHub - TabularEditor/Scripts: Community repository for sharing and discussing scripts for use with Tabular Editor
✨ Follow us on LinkedIn and to our YouTube channel
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.
- littlemojopuppyCommunity Champion
parry2k this is perfect! Thank you!
- parry2kSuper User
littlemojopuppy WOW 😲 I wish I could help on this but I have some time constraints. If there is something quick I can answer, please let me know. Good luck!
- littlemojopuppyCommunity Champion
Hi parry2k
I appreciate you looking at this and I hope you're doing well.
If you have a sample script of something similar I could use to demo to a real C sharp developer, that would be enough!
But thank you! 🙂
- mahoneypatMicrosoft Employee
I don't know enough C# to help easily. One question though. If you already have the base measures and your new calculation items, why can't you bulk delete all the bad measures in TE? You would then have the base measures and the ~25 calc items to be used with each.
Or are you saying that all reports are built and you need to update all those measures with the below?
CALCULATE([Base Measure], CalcGrp[Name] = "CalcItem")
Pat
- littlemojopuppyCommunity Champion
Hi mahoneypat I need them to be available for users. And I don't want to have to manually correct or recreate 40% of 2400 measures.
I'd actually prefer to delete all the measures and recreate them via script so they use the calculation groups/items. That way (hypothetically) if the company adopted a new fiscal year, I'd only have to change it once and not find every measure where YTD is calculated.
- bcdobbsCommunity Champion
Have you seen Phil Seamark's blog series on this?
https://dax.tips/2020/07/09/using-visual-studio-code-with-power-bi/