March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi!
I'm trying to use an if statement inside of a measure to determine which of two different generateseries functions to run. This is based on whether or not the parameter is negative. I'm getting an error that states "The function expects a table expression for argument, but a string or numeric expression was used." I've also tried to use the SIGN function instead of > 0 but it gives the same error. I also tried SWITCH instead of IF, but again, same error.
The measure works perfectly if I replace "NumTestedRange" in the FilteredTbl variable with "PositiveNumTestedRange" or "NegativeNumTestedRange".
I can't seem to get a single generateseries function to work because if I provide a negative value in the "SwingCriteria" parameter then my series would look like 100...80 when I need to flip it and have it be 80...100. Can someone help me figure out a workaround here?
test =
VAR SelectedSchool = SELECTEDVALUE(AssessmentData[BEDSCODE])
VAR PositiveNumTestedRange = GENERATESERIES( 'My Measures'[SelectedSchoolNumTested], 'My Measures'[SelectedSchoolNumTested] + ('My Measures'[SelectedSchoolNumTested] * SwingCriteria[SwingCriteria Value]) )
VAR NegativeNumTestedRange = GENERATESERIES( 'My Measures'[SelectedSchoolNumTested] + ('My Measures'[SelectedSchoolNumTested] * SwingCriteria[SwingCriteria Value]), 'My Measures'[SelectedSchoolNumTested] )
VAR NumTestedRange = IF( SwingCriteria[SwingCriteria Value] > 0, PositiveNumTestedRange, NegativeNumTestedRange )
VAR FilteredTbl = CALCULATETABLE(AssessmentData,
ALL(AssessmentData),
AssessmentData[BEDSCODE] <> SelectedSchool,
AssessmentData[NUM_TESTED] IN NumTestedRange
)
RETURN
COUNTROWS(FilteredTbl)
Solved! Go to Solution.
Since IF and SWITCH return scalar values, you need to shift the IF logic to start/end variables and then use these variables in GENERATESERIES:
test =
VAR SelectedSchool =
SELECTEDVALUE ( AssessmentData[BEDSCODE] )
VAR SeriesStart =
IF (
SwingCriteria[SwingCriteria Value] > 0,
[SelectedSchoolNumTested],
[SelectedSchoolNumTested] + ( [SelectedSchoolNumTested] * SwingCriteria[SwingCriteria Value] )
)
VAR SeriesEnd =
IF (
SwingCriteria[SwingCriteria Value] > 0,
[SelectedSchoolNumTested] + ( [SelectedSchoolNumTested] * SwingCriteria[SwingCriteria Value] ),
[SelectedSchoolNumTested]
)
VAR NumTestedRange =
GENERATESERIES ( SeriesStart, SeriesEnd )
VAR FilteredTbl =
CALCULATETABLE (
AssessmentData,
ALL ( AssessmentData ),
AssessmentData[BEDSCODE] <> SelectedSchool,
AssessmentData[NUM_TESTED] IN NumTestedRange
)
RETURN
COUNTROWS ( FilteredTbl )
Proud to be a Super User!
Since IF and SWITCH return scalar values, you need to shift the IF logic to start/end variables and then use these variables in GENERATESERIES:
test =
VAR SelectedSchool =
SELECTEDVALUE ( AssessmentData[BEDSCODE] )
VAR SeriesStart =
IF (
SwingCriteria[SwingCriteria Value] > 0,
[SelectedSchoolNumTested],
[SelectedSchoolNumTested] + ( [SelectedSchoolNumTested] * SwingCriteria[SwingCriteria Value] )
)
VAR SeriesEnd =
IF (
SwingCriteria[SwingCriteria Value] > 0,
[SelectedSchoolNumTested] + ( [SelectedSchoolNumTested] * SwingCriteria[SwingCriteria Value] ),
[SelectedSchoolNumTested]
)
VAR NumTestedRange =
GENERATESERIES ( SeriesStart, SeriesEnd )
VAR FilteredTbl =
CALCULATETABLE (
AssessmentData,
ALL ( AssessmentData ),
AssessmentData[BEDSCODE] <> SelectedSchool,
AssessmentData[NUM_TESTED] IN NumTestedRange
)
RETURN
COUNTROWS ( FilteredTbl )
Proud to be a Super User!
@DataInsights ,
This worked perfectly. Thank you so much! I tried various combinations but for some reason never thought to try that particular one. I appreciate you taking the time to help and explain why what I was trying to do wasn't working!
Thanks again!
Glad to hear that worked!
Proud to be a Super User!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
114 | |
76 | |
57 | |
52 | |
44 |
User | Count |
---|---|
167 | |
117 | |
63 | |
57 | |
50 |