I have been experimenting with Tabular Editor and Power BI Desktop for a few months now and looking at and using Tabular Editor to create KPIs.
The tutorials that I used are Creating KPIs in Power Bi Desktop, Tabular Models for Power Bi & Excel both from SQLBi.com, and Calculation Groups with Tabular Editor from Debbies MS Power Biazure Blog, which I found incredibly useful. I rewrote the measures using the practise reports and then enabled them to work on another practise report adapting the code. There is something extremely satisfying about writing code and seeing the impact in a visual manner and then building on your knowledge to really embed the skills.
In the report that I was using, I have a slicer which enables the user to select between profits, costs and sales to visualise performance. I could bring in the KPIs separately for each of those measures but in line with the report, it would be useful to enable the user to use the same features in each page and swap by using the slicer.
There is a fantastic function called SWITCH() which is basically similar to a nested if that allows different Measures to occur depending upon different conditions. If you haven’t found this yet, then Curbal’s glossary is brilliant for finding out what different functions do which you can read here.
If you follow the tutorials above, they’ll show you how to create KPIs and I added to this by creating a Selected Metric to switch between the three values
This measure enables you to create a slicer to choose which measure to show in the report and forms the basis of my target expression.
From there, I created my Status expression:
And then from there, the Trend expression: