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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
olimilo
Post Prodigy
Post Prodigy

IF(HASONEFILTER()) with a filter selection?

So I'm trying to convert this logic to DAX. I have three different formulas that I use to get the utilization rate of a person that depends on their position. If:

 

1. Contractor
Utilization (C) = (Days Worked + OOF Days) / (Days Worked + OOF Days)

2. Other
Utilization (O) = (Days Worked + Travelling Days + OOF Days) / (Days Worked + Travelling Days + OOF Days)
* Essentially for Contractor/Other, if the sum of all required values > 0, 100%, but I have to use the formula and not the IF-ELSE

3. Regular Employees (General Formula)
Utilization (R) = (Days Worked + Travelling Days + OOF Days) / Possible Working Days

Basically, it should use the general formula if only the Regular Employees filter is selected, or if all filters are selected (ie: fallback). Is it possible to use HASONEFILTER with an "equals to" value? Like:

 

HASONEFILTER([Type] = "Contractor")

 

I'm trying this, but I'm not getting the correct value. If I have all three values selected, it just gets the formula for the Other and not the general formula.

 

Utilization Rate = 
	IF(CONTAINS(test, [Type], "Other"),
		CALCULATE(
			DIVIDE(
				SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days]),
				SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days])
			)
		)
		,
		IF(CONTAINS(test, [Type], "Subcontractor"),
			CALCULATE(
				DIVIDE(
					SUM([Days Worked]) + SUM(test[OOF Days]),
					SUM([Days Worked]) + SUM(test[OOF Days])
				)
			)
			,
			CALCULATE(
				DIVIDE(
					SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days]),
					SUM(test[Possible Workdays Per Month])
				)
			)
		)
	)

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @olimilo,

 

You can try to use below formuals:

 

Utilization Rate(Calculate Column) = 
SWITCH(Sheet3[Type],
	"O",
			DIVIDE(
				[Days Worked] + Sheet3[OOF Days]+ Sheet3[Travel Days],
				[Days Worked] + Sheet3[OOF Days] + Sheet3[Travel Days]
			),
	"C",
				DIVIDE(
					[Days Worked] + Sheet3[OOF Days],
					[Days Worked] + Sheet3[OOF Days]
				),
	"R",				
				DIVIDE(
					Sheet3[Days Worked] + Sheet3[OOF Days] + Sheet3[Travel Days],
					Sheet3[Possible Working Days]
				)
	)


Utilization Rate(Measure) = 
var currtype=if(HASONEVALUE(Sheet3[Type]),VALUES(Sheet3[Type]),BLANK())
var currType2=LASTNONBLANK(Sheet3[Type],[Type])
return
SWITCH(currtype,
	"O",
			DIVIDE(
				SUM([Days Worked]) + SUM(Sheet3[OOF Days]) + SUM(Sheet3[Travel Days]),
				SUM([Days Worked]) + SUM(Sheet3[OOF Days]) + SUM(Sheet3[Travel Days])
			),
	"C",
				DIVIDE(
					SUM([Days Worked]) + SUM(Sheet3[OOF Days]),
					SUM([Days Worked]) + SUM(Sheet3[OOF Days])
				),
	"R",				
				DIVIDE(
					SUM(Sheet3[Days Worked]) + SUM(Sheet3[OOF Days]) + SUM(Sheet3[Travel Days]),
					SUM(Sheet3[Possible Working Days])
				)
	)

 

Capture.PNG

 

>>Is there something I can use to replace the MAX() as the switch case for this?

You can use lastnonblank or isonevalue to get the current row value in measure.

 

Regards,

Xiaoxin Sheng

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @olimilo,

 

>>Basically, it should use the general formula if only the Regular Employees filter is selected, or if all filters are selected (ie: fallback). Is it possible to use HASONEFILTER with an "equals to" value? Like:
You can try to use below measure which used to get the select item from slicer:

Selected Item=IF(HASONEVALUE(Table[Column]),VALUES(Table[Column]),BLANK)

 

>>I'm trying this, but I'm not getting the correct value. If I have all three values selected, it just gets the formula for the Other and not the general formula.

For your requirement, you can try to use switch function with calculate column:

Calculate column:
Utilization Rate = 
SWITCH(test[Type],
	"Other",
			DIVIDE(
				SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days]),
				SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days])
			),
	"Subcontractor",
				DIVIDE(
					SUM([Days Worked]) + SUM(test[OOF Days]),
					SUM([Days Worked]) + SUM(test[OOF Days])
				),
				DIVIDE(
					SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days]),
					SUM(test[Possible Workdays Per Month])
				)
	)

Measure:
Utilization Rate = 
SWITCH(MAX(test[Type]),
	"Other",
			DIVIDE(
				SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days]),
				SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days])
			),
	"Subcontractor",
				DIVIDE(
					SUM([Days Worked]) + SUM(test[OOF Days]),
					SUM([Days Worked]) + SUM(test[OOF Days])
				),
				DIVIDE(
					SUM([Days Worked]) + SUM(test[OOF Days]) + SUM(test[Travelling Days]),
					SUM(test[Possible Workdays Per Month])
				)
	)

 

 

If above not help, please share some sample data to test.

 

Regards,

Xiaoxin Sheng

Hi @Anonymous

 

Thanks for the solution. I have since reordered my data and with the given measure, it only gets the first case (just the Other) if I have all three types (Regular, Contractor, Other) selected and does not fall to the fall back formula (ie: the else case). Is there something I can use to replace the MAX() as the switch case for this?

 

Edit: I just checked, the MAX() only gets the last entry when you sort the 3 types, so it gets Subcontractor (since it goes last when you sort the 3 types alphabetically).

Anonymous
Not applicable

Hi @olimilo,

 

You can try to use below formuals:

 

Utilization Rate(Calculate Column) = 
SWITCH(Sheet3[Type],
	"O",
			DIVIDE(
				[Days Worked] + Sheet3[OOF Days]+ Sheet3[Travel Days],
				[Days Worked] + Sheet3[OOF Days] + Sheet3[Travel Days]
			),
	"C",
				DIVIDE(
					[Days Worked] + Sheet3[OOF Days],
					[Days Worked] + Sheet3[OOF Days]
				),
	"R",				
				DIVIDE(
					Sheet3[Days Worked] + Sheet3[OOF Days] + Sheet3[Travel Days],
					Sheet3[Possible Working Days]
				)
	)


Utilization Rate(Measure) = 
var currtype=if(HASONEVALUE(Sheet3[Type]),VALUES(Sheet3[Type]),BLANK())
var currType2=LASTNONBLANK(Sheet3[Type],[Type])
return
SWITCH(currtype,
	"O",
			DIVIDE(
				SUM([Days Worked]) + SUM(Sheet3[OOF Days]) + SUM(Sheet3[Travel Days]),
				SUM([Days Worked]) + SUM(Sheet3[OOF Days]) + SUM(Sheet3[Travel Days])
			),
	"C",
				DIVIDE(
					SUM([Days Worked]) + SUM(Sheet3[OOF Days]),
					SUM([Days Worked]) + SUM(Sheet3[OOF Days])
				),
	"R",				
				DIVIDE(
					SUM(Sheet3[Days Worked]) + SUM(Sheet3[OOF Days]) + SUM(Sheet3[Travel Days]),
					SUM(Sheet3[Possible Working Days])
				)
	)

 

Capture.PNG

 

>>Is there something I can use to replace the MAX() as the switch case for this?

You can use lastnonblank or isonevalue to get the current row value in measure.

 

Regards,

Xiaoxin Sheng

Hi Xiaoxin!

 

Sample data in here:

 

CountryTypePossible Working DaysDays WorkedOOF DaysTravel DaysUT Rate
USAR754810381%
USAC9631100%
CanadaC2200100%
MexicoR853872987%
MexicoC353230100%
MexicoO5500100%
BrazilR64378477%
BrazilC131302100%
El SalvadorC2200100%
HaitiC1101100%
PeruC1101100%

 

The formula for the utilization varies according to type (R, C, O). Also, why was there a MAX() on the measure? Does that mean we're getting all three types in the filter?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.