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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
abanar2
Frequent Visitor

Need help with my measure

Hello Community, 

 

I’m currently working on a project where I need to calculate Key Performance Indicators (KPIs) using a DAX measure, but I’m having some difficulties and could use your help.

I have a dataset with the following columns:

Column NameMeaning
YearYear of the data row
QuarterQuarter of the data row
Site_IDSite_ID of the data row
KPI_IDKPI_ID of the data row
KPI_NameKPI_Name of the data row
Is_Total_KPIYes: the selected KPI used as itself as KPI Group
KPI_GroupGroup of the KPIs
KPI_ValueThe value for the selected year, quarter, site and KPI
Dividend_IDThe ID of the KPI what we use as dividend for in the KPI Group calculation
Divisor_IDThe ID of the KPI what we use as divisor for in the KPI Group calculation

 

I need to create a measure that can handle three different calculation scenarios:

  1. When we calculate a division between KPI pairs (e.g., KPI2 / KPI1)
  2. When we want to use a KPI, which is already a member of a KPI Group, as a KPI Group in itself (e.g., KPI1)
  3. When our KPI isn’t a member of any calculation but we evaluate it as itself (e.g., KPI3)

 

Ultimately, I want to visualize the KPI_Group_Values with the Year, Quarter, Site_ID, and KPI_Group_Name in a table or matrix.

 

I will paste a data sample into the comments.

 

At the end I would like to visualize the KPI_Group_Values with the Year, the Quarter, the Site_ID, The KPI_Group_Name in a table or in a matrix. I calculated the aim KPI_Group_Values into a table what you can find above:

 

Year Quarter Site_ID KPI_Group KPI_Group_Value

20211Site1Training Planned79
20212Site1Training Planned75
20213Site1Training Planned67
20214Site1Training Planned77
20211Site1% Training Done during the Quarter16.46%
20212Site1% Training Done during the Quarter21.33%
20213Site1% Training Done during the Quarter26.87%
20214Site1% Training Done during the Quarter36.36%
20211Site1Number of Focus Rooms in the Office100
20212Site1Number of Focus Rooms in the Office100
20213Site1Number of Focus Rooms in the Office100
20214Site1Number of Focus Rooms in the Office100
20211Site2Training Planned34
20212Site2Training Planned25
20213Site2Training Planned73
20214Site2Training Planned10
20211Site2% Training Done during the Quarter235.29%
20212Site2% Training Done during the Quarter136.00%
20213Site2% Training Done during the Quarter102.74%
20214Site2% Training Done during the Quarter180.00%
20211Site2Number of Focus Rooms in the Office70
20212Site2Number of Focus Rooms in the Office70
20213Site2Number of Focus Rooms in the Office70
20214Site2Number of Focus Rooms in the Office70
20221Site1Training Planned33
20222Site1Training Planned71
20223Site1Training Planned11
20224Site1Training Planned49
20221Site1% Training Done during the Quarter109.09%
20222Site1% Training Done during the Quarter123.94%
20223Site1% Training Done during the Quarter318.18%
20224Site1% Training Done during the Quarter179.59%
20221Site1Number of Focus Rooms in the Office90
20222Site1Number of Focus Rooms in the Office90
20223Site1Number of Focus Rooms in the Office90
20224Site1Number of Focus Rooms in the Office110
20221Site2Training Planned67
20222Site2Training Planned96
20223Site2Training Planned29
20224Site2Training Planned83
20221Site2% Training Done during the Quarter73.13%
20222Site2% Training Done during the Quarter34.38%
20223Site2% Training Done during the Quarter331.03%
20224Site2% Training Done during the Quarter32.53%
20221Site2Number of Focus Rooms in the Office70
20222Site2Number of Focus Rooms in the Office70
20223Site2Number of Focus Rooms in the Office70
20224Site2Number of Focus Rooms in the Office72
6 REPLIES 6
v-tangjie-msft
Community Support
Community Support

Hi @abanar2 ,

 

Are the numbers in your post the expected results you want? If so, can you give an example of how to get this line of results in conjunction with your example data (REPLY 2)?

2021 1 Site1 % Training Done during the Quarter 16.46%

 

Best Regards,

Neeko Tang

20211Site1% Training Done during the Quarter16.46%

Dividend row:

YearQuarterSite_IDKPI_IDKPI_NameIs_Total_KPIKPI_GroupKPI_ValueDividend_IDDivisor_ID
20211Site1KPI1Training PlannedYes% Training Done during the Quarter79KPI2KPI1

 

Divisor row:

20211Site1KPI2Training DoneNo% Training Done during the Quarter13KPI2KPI1

 

13 / 79 = 0.164556962 

Hi @abanar2 ,

 

We can create two tables.

Table 2 = FILTER(SELECTCOLUMNS('Table',[Year],[Quarter],[Site_ID],[KPI_Name],[KPI_Value]),[KPI_Name] IN {"Training Planned","Number of Focus Rooms in the Office"})
Table 3 = 
var _a=DISTINCT(SELECTCOLUMNS('Table',[Year],[Quarter],[Site_ID]))
var _b={"% Training Done during the Quarter"}
RETURN CROSSJOIN(_a,_b)

We create a calculated column on Table 3.

Table_KPI_Value = 
var _a=CALCULATE(SUM('Table'[KPI_Value]),FILTER('Table',[Year]=EARLIER('Table 3'[Table_Year]) && [Quarter]=EARLIER('Table 3'[Table_Quarter]) && [Site_ID]=EARLIER('Table 3'[Table_Site_ID]) && [KPI_ID]="KPI1"))
var _b=CALCULATE(SUM('Table'[KPI_Value]),FILTER('Table',[Year]=EARLIER('Table 3'[Table_Year]) && [Quarter]=EARLIER('Table 3'[Table_Quarter]) && [Site_ID]=EARLIER('Table 3'[Table_Site_ID]) && [KPI_ID]="KPI2"))
RETURN DIVIDE(_b,_a)

Then we can create a table.

Table 4 = 
var _a=SELECTCOLUMNS('Table 2',[Table_Year],[Table_Quarter],[Table_Site_ID],[Table_KPI_Name],[Table_KPI_Value])
var _b=SELECTCOLUMNS('Table 3',[Table_Year],[Table_Quarter],[Table_Site_ID],"Table_KPI_Name",[Value],[Table_KPI_Value])
RETURN UNION(_a,_b)

vtangjiemsft_0-1721896050492.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Hi @v-tangjie-msft,

 

Thank you for your ideas.


In my real case I have about 50 KPI Groups and this number can change, so maybe in the future I will have less or more. I can`t hardcode anyting into my script because then it would be very painful to maintane. 

Hi @abanar2 ,

 

If you want to avoid hard-coding, you can modify the DAX expression like this:

Table 2 = FILTER(SELECTCOLUMNS('Table',[Year],[Quarter],[Site_ID],[KPI_Name],[KPI_Value]),[KPI_Name] IN SELECTCOLUMNS(FILTER('Table',[Is_Total_KPI]="Yes"),[KPI_Name]))

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

abanar2
Frequent Visitor

This is the sample dataset.

YearQuarterSite_IDKPI_IDKPI_NameIs_Total_KPIKPI_GroupKPI_ValueDividend_IDDivisor_ID
20211Site1KPI1Training PlannedYes% Training Done during the Quarter79KPI2KPI1
20212Site1KPI1Training PlannedYes% Training Done during the Quarter75KPI2KPI1
20213Site1KPI1Training PlannedYes% Training Done during the Quarter67KPI2KPI1
20214Site1KPI1Training PlannedYes% Training Done during the Quarter77KPI2KPI1
20221Site1KPI1Training PlannedYes% Training Done during the Quarter33KPI2KPI1
20222Site1KPI1Training PlannedYes% Training Done during the Quarter71KPI2KPI1
20223Site1KPI1Training PlannedYes% Training Done during the Quarter11KPI2KPI1
20224Site1KPI1Training PlannedYes% Training Done during the Quarter49KPI2KPI1
20211Site2KPI1Training PlannedYes% Training Done during the Quarter34KPI2KPI1
20212Site2KPI1Training PlannedYes% Training Done during the Quarter25KPI2KPI1
20213Site2KPI1Training PlannedYes% Training Done during the Quarter73KPI2KPI1
20214Site2KPI1Training PlannedYes% Training Done during the Quarter10KPI2KPI1
20221Site2KPI1Training PlannedYes% Training Done during the Quarter67KPI2KPI1
20222Site2KPI1Training PlannedYes% Training Done during the Quarter96KPI2KPI1
20223Site2KPI1Training PlannedYes% Training Done during the Quarter29KPI2KPI1
20224Site2KPI1Training PlannedYes% Training Done during the Quarter83KPI2KPI1
20211Site1KPI2Training DoneNo% Training Done during the Quarter13KPI2KPI1
20212Site1KPI2Training DoneNo% Training Done during the Quarter16KPI2KPI1
20213Site1KPI2Training DoneNo% Training Done during the Quarter18KPI2KPI1
20214Site1KPI2Training DoneNo% Training Done during the Quarter28KPI2KPI1
20221Site1KPI2Training DoneNo% Training Done during the Quarter36KPI2KPI1
20222Site1KPI2Training DoneNo% Training Done during the Quarter88KPI2KPI1
20223Site1KPI2Training DoneNo% Training Done during the Quarter35KPI2KPI1
20224Site1KPI2Training DoneNo% Training Done during the Quarter88KPI2KPI1
20211Site2KPI2Training DoneNo% Training Done during the Quarter80KPI2KPI1
20212Site2KPI2Training DoneNo% Training Done during the Quarter34KPI2KPI1
20213Site2KPI2Training DoneNo% Training Done during the Quarter75KPI2KPI1
20214Site2KPI2Training DoneNo% Training Done during the Quarter18KPI2KPI1
20221Site2KPI2Training DoneNo% Training Done during the Quarter49KPI2KPI1
20222Site2KPI2Training DoneNo% Training Done during the Quarter33KPI2KPI1
20223Site2KPI2Training DoneNo% Training Done during the Quarter96KPI2KPI1
20224Site2KPI2Training DoneNo% Training Done during the Quarter27KPI2KPI1
20211Site1KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office10000
20212Site1KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office10000
20213Site1KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office10000
20214Site1KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office10000
20221Site1KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office9000
20222Site1KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office9000
20223Site1KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office9000
20224Site1KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office11000
20211Site2KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office7000
20212Site2KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office7000
20213Site2KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office7000
20214Site2KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office7000
20221Site2KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office7000
20222Site2KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office7000
20223Site2KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office7000
20224Site2KPI3Number of Focus Rooms in the OfficeYesNumber of Focus Rooms in the Office7200

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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