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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
rsanyoto
Helper III
Helper III

Using variable in order to return values from max

Hello everyone,

 

I am stuck with the following scenairo:

 

I have a report that shows measures visualized in Slicer and related infographics such as bar charts, tables etc.

 

I would like to create a measure based on the following requirements:

 

  1. If one of the "groei.." or "instroom.." measures in the variable Firsmonth are selected in the Slicer then show the output based on the max of the field Bezetting[Month]. Other wise blank.
  2. If one of the "uitstroom..." measures mention in the variable Secondmonth are selected in the slicer then show the outpute based on the max of the field Bezetting[Uitstroom Month]. Other wise blank.

 

I currently have the following measure but unfortunatly it doesnt work. 

 

Measure B = 

VAR FirstMonth = IF(
SWITCH(TRUE(),
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei % afgelopen maand",'Kengetallen groei'[groei % mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei % laatste 12 maand",'Kengetallen groei'[groei % 12 mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei in aantal mdw afgelopen maand",'Kengetallen groei'[groei aantal mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei in aantal mdw laatste 12 maand",'Kengetallen groei'[groei aantal 12 mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw ingestroomd afgelopen maand",'Kengetallen groei'[instroom mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw ingestroomd laatste 12 maand",'Kengetallen groei'[instroom 12 mnd]),
MAX(Bezetting[Month]),
BLANK())

VAR SecondMonth = IF(
SWITCH(TRUE(),
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw uitgestroomd afgelopen maand",'Kengetallen groei'[uitstroom mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw uitgestroomd laatste 12 maand",'Kengetallen groei'[uitstroom 12 mnd]),
MAX(Bezetting[Uitstroom month]),
BLANK())

return BLANK()

 

 

I cant find any solution to change my current measure. Any help/suggestions would be very welcome. 

 

Kind regards!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @rsanyoto  ,

The last return of the function you used should be followed by the value you want to display. You return blank() here, so the results must be empty

 

If you have a date requirement here, you can write as follows:

Measure B = 
VAR _FirstMonth = IF(
SWITCH(TRUE(),
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei % afgelopen maand",'Kengetallen groei'[groei % mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei % laatste 12 maand",'Kengetallen groei'[groei % 12 mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei in aantal mdw afgelopen maand",'Kengetallen groei'[groei aantal mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei in aantal mdw laatste 12 maand",'Kengetallen groei'[groei aantal 12 mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw ingestroomd afgelopen maand",'Kengetallen groei'[instroom mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw ingestroomd laatste 12 maand",'Kengetallen groei'[instroom 12 mnd]),
MAX(Bezetting[Month]),
BLANK())

VAR _SecondMonth = IF(
SWITCH(TRUE(),
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw uitgestroomd afgelopen maand",'Kengetallen groei'[uitstroom mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw uitgestroomd laatste 12 maand",'Kengetallen groei'[uitstroom 12 mnd]),
MAX(Bezetting[Uitstroom month]),
BLANK())

return 
SWITCH(TRUE(),
date = date1, _FirstMonth,
date = date2, _SecondMonth,
blank())

For the usage of VaR, you can see the following documents:

https://dax.guide/st/var/

 

If my answer is not what you need, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Best Regards,

Liu Yang

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @rsanyoto  ,

The last return of the function you used should be followed by the value you want to display. You return blank() here, so the results must be empty

 

If you have a date requirement here, you can write as follows:

Measure B = 
VAR _FirstMonth = IF(
SWITCH(TRUE(),
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei % afgelopen maand",'Kengetallen groei'[groei % mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei % laatste 12 maand",'Kengetallen groei'[groei % 12 mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei in aantal mdw afgelopen maand",'Kengetallen groei'[groei aantal mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Groei in aantal mdw laatste 12 maand",'Kengetallen groei'[groei aantal 12 mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw ingestroomd afgelopen maand",'Kengetallen groei'[instroom mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw ingestroomd laatste 12 maand",'Kengetallen groei'[instroom 12 mnd]),
MAX(Bezetting[Month]),
BLANK())

VAR _SecondMonth = IF(
SWITCH(TRUE(),
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw uitgestroomd afgelopen maand",'Kengetallen groei'[uitstroom mnd],
VALUES('Kengetallen groei'[Groei kengetallen]) = "Aantal mdw uitgestroomd laatste 12 maand",'Kengetallen groei'[uitstroom 12 mnd]),
MAX(Bezetting[Uitstroom month]),
BLANK())

return 
SWITCH(TRUE(),
date = date1, _FirstMonth,
date = date2, _SecondMonth,
blank())

For the usage of VaR, you can see the following documents:

https://dax.guide/st/var/

 

If my answer is not what you need, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Best Regards,

Liu Yang

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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