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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
littlemojopuppy
Community Champion
Community Champion

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):

  1. Sample code to loop through a list of base measures and create the necessary time intelligence measures
  2. Resources to educate a C sharp programmer on how this can be done
  3. Any other assistance!
  4. Resources on how I can quickly learn enough C sharp to do this myself 😕

Would appreciate any help that anyone could provide.

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@littlemojopuppy I'm sure this will get you going. GitHub - TabularEditor/Scripts: Community repository for sharing and discussing scripts for use with...

 

 

Follow us on LinkedIn and YouTube.gif 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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
bcdobbs
Super User
Super User

Have you seen Phil Seamark's blog series on this?

 

https://dax.tips/2020/07/09/using-visual-studio-code-with-power-bi/



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!!
mahoneypat
Employee
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

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.

parry2k
Super User
Super User

@littlemojopuppy I'm sure this will get you going. GitHub - TabularEditor/Scripts: Community repository for sharing and discussing scripts for use with...

 

 

Follow us on LinkedIn and YouTube.gif 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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k this is perfect!  Thank you!

parry2k
Super User
Super 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!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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!  🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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