cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
littlemojopuppy
Super User
Super User

DAX Query With Optional Parameters

Hi!  Would like to ask for some help with something.  Got a Power BI paginated report based on this DAX Query.

EVALUATE
    (
        FILTER (
            ADDCOLUMNS (
                CALCULATETABLE (
                    Placements,
                    NOT ( Departments[Department] IN { "BEA", "CORP", "IR" } ),
                    NOT ( Clients[clientCorporationID] IN { 169298, 234729 } ),
                    NOT ( Placements[terminationReason] IN { "DNS", "Did Not Start" } ),
                    VALUES ( Placements[terminationReason] ),
                    Placements[isDeleted] = FALSE (),
                    USERELATIONSHIP ( 'Calendar'[FullDate], Placements[dateAdded] )
                ),
                "Vertical", RELATED ( Verticals[Vertical] ),
                "Branch", RELATED ( Branches[Branch] ),
                "MidAtlantic", RELATED ( MidAtlantic[midatlantic] ),
                "ClientName", RELATED ( Clients[name] ),
                "JobTitle", RELATED ( JobOrders[title] ),
                "JobOwner", RELATED ( Users[name] )
            ),
            RELATED ( Verticals[Vertical] ) = @Vertical
			&& RELATED ( Branches[Branch] ) = @Branch
			&& RELATED ( MidAtlantic[midatlantic] ) = @MidAtlantic
			&& RELATED ( EmploymentTypes[employmentType] ) = @EmploymentTypes
			&& RELATED ( 'Calendar'[FullDate] ) >= @StartDate
            && RELATED ( 'Calendar'[FullDate] ) <= @EndDate
        )   
    )

Only StartDate and EndDate parameters are required.  The other four parameters are optional, and could have one or more values if provided.  I've spent the last few hours googling looking for anything.  Closest thing that seemed promising was this article, but unfortunately didn't help.

 

Could anyone provide some help or at least point me in the right direction?  Thank you!  🙂

1 ACCEPTED SOLUTION
littlemojopuppy
Super User
Super User

After four days of trying, best solution possible: blow the whole thing away and start over

View solution in original post

3 REPLIES 3
littlemojopuppy
Super User
Super User

After four days of trying, best solution possible: blow the whole thing away and start over

lbendlin
Super User
Super User

Use COALESCE to decide what to provide in case the parameter is empty.

Hi @lbendlin ... a null/blank value would be legitimate (user may not want to filter on something).

 

For context, this is for a paginated report in a Power BI report.  User will have a visual and this would be so they could see the detail behind a particular data point in that visual.  Passing parameters into a paginated report has been the biggest pain in the a$$ I've encountered in months...

 

In this article it says "use the query designer for the data source to help build a parameterized query".  So I used the query designer and now I have this...

 

DEFINE 
VAR vFromCalendarFullDate1 =
IF (
    PATHLENGTH ( @FromCalendarFullDate ) = 1,
    IF (
        @FromCalendarFullDate <> "",
        @FromCalendarFullDate,
        BLANK ()
    ),
    IF (
        PATHITEM (
            @FromCalendarFullDate,
            2
        ) <> "",
        PATHITEM (
            @FromCalendarFullDate,
            2
        ),
        BLANK ()
    )
)
VAR vFromCalendarFullDate1ALL =
PATHLENGTH ( @FromCalendarFullDate ) > 1
    && PATHITEM (
        @FromCalendarFullDate,
        1,
        1
    ) < 1
VAR vToCalendarFullDate1 =
IF (
    PATHLENGTH ( @ToCalendarFullDate ) = 1,
    IF (
        @ToCalendarFullDate <> "",
        @ToCalendarFullDate,
        BLANK ()
    ),
    IF (
        PATHITEM (
            @ToCalendarFullDate,
            2
        ) <> "",
        PATHITEM (
            @ToCalendarFullDate,
            2
        ),
        BLANK ()
    )
)
VAR vToCalendarFullDate1ALL =
PATHLENGTH ( @ToCalendarFullDate ) > 1
    && PATHITEM (
        @ToCalendarFullDate,
        1,
        1
    ) < 1
EVALUATE 
	SUMMARIZECOLUMNS(
		'Placements'[placementID], 
		'Verticals'[Vertical], 
		'Branches'[Branch], 
		'EmploymentTypes'[employmentType], 
		'Placements'[status], 
		'Placements'[dateAdded], 
		'Placements'[dateBegin], 
		'Placements'[dateEnd], 
		'Clients'[name], 
		'JobOrders'[title], 
		'Users'[name], 
		FILTER(
			VALUES('Calendar'[FullDate]), 
			(vFromCalendarFullDate1ALL || 'Calendar'[FullDate] >= DATEVALUE(vFromCalendarFullDate1) + TIMEVALUE(vFromCalendarFullDate1)) && 
			(vToCalendarFullDate1ALL || 'Calendar'[FullDate] <= DATEVALUE(vToCalendarFullDate1) + TIMEVALUE(vToCalendarFullDate1))
		), 
		RSCustomDaxFilter(@VerticalsVertical,EqualToCondition,[Verticals].[Vertical],String), 
		RSCustomDaxFilter(@BranchesBranch,EqualToCondition,[Branches].[Branch],String), 
		RSCustomDaxFilter(@MidAtlanticmidatlantic,EqualToCondition,[MidAtlantic].[midatlantic],String), 
		RSCustomDaxFilter(@EmploymentTypesemploymentType,EqualToCondition,[EmploymentTypes].[employmentType],String), 
		FILTER(
			VALUES('Departments'[Department]), 
			('Departments'[Department] <> "BEA") && ('Departments'[Department] <> "Corp") && ('Departments'[Department] <> "IR")
		), 
		FILTER(
			VALUES('Clients'[clientCorporationID]), 
			('Clients'[clientCorporationID] <> 169298) && ('Clients'[clientCorporationID] <> 234729)
		), 
		FILTER(
			VALUES('Placements'[terminationReason]), 
			('Placements'[terminationReason] <> "Did Not Start") && ('Placements'[terminationReason] <> "DNS")
		), 
		FILTER(
			VALUES('Placements'[isDeleted]), 
			('Placements'[isDeleted] = False)
		)
	)

 

But when I try to publish the paginated report to the Power BI service, error.  

Screenshot 2021-08-10 143413.png

Helpful resources

Announcements
collabdays lisbon

CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.