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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
johnsiah91
Frequent Visitor

Translating where clause or statement in SQL to Power BI

Hi,

 

I am having a SQL query to get the number of permits falling under the following where statement:

WHERE (P.APPLYDATE BETWEEN @STARTDATE AND @ENDDATE
OR P.ISSUEDATE BETWEEN @STARTDATE AND @ENDDATE)

 

I loaded the code in Power BI and named this PermitDim. I then created a DateDim, and then link APPLYDATE from PermitDim to CalendarDate in DateDim, and have an inactive relationship that points ISSUEDATE to CalendarDate

 

I am trying to create a measure in Power BI that will give me the count of permits that falls under the Where statement above. I tried using USERELATIONSHIP but it does not work because I am only pointing one date field at one time. Is there a way to tell DAX to look at both relationships at the same time and then give me a count?

 

Any help will be greatly appreciated! Thanks!

2 REPLIES 2
johnsiah91
Frequent Visitor

@CNENFRNL 

Thank you so much for this. I tried building on your DAX code but got stuck again. Please allow me to expand a little further.

 

To recap:

johnsiah91_0-1653321651795.png

This is what I get from the where clause

WHERE (P.APPLYDATE BETWEEN @STARTDATE AND @ENDDATE
OR P.ISSUEDATE BETWEEN @STARTDATE AND @ENDDATE)

 

My goal is to get an average of the sum of the PR_TIME_DAYS based on COMPLETEDATE. 

And this is what I have done so far:

Using the code you shared with me, I am able to get the count of COMPLETEDATE, which is 5.

 

johnsiah91_1-1653323919484.png

The question now is how do I get the sum of the PR_TIME_DAYS based on the 5 rows, which is supposed to 20.

 

Thanks!

 

CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1653206578527.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.