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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Converting Sql query to DAX

Hi All, 

 

I'm having some trouble converting this Sql query to DAX

 

select AGMST_CUSMST_ID, OrgSTS_ID, BookingType, month(orgstartdate) [Month], sum(CountAll) Volume, 
Count(distinct concat(id, OrgSTARTDATE)) Legs,
sum(RevenueAll) BaseRevenue, sum(RevenueEURALL) EURRevenue, sum(Price)
from PasF_BookingJourney b
where AGMST_CUSMST_ID = '525775'
and regdate < '2020-03-01'
and OrgSTARTDATE >= '2020-03-01'
and (CANXDATE >= '2020-03-01' or CANXDATE is null)
group by AGMST_CUSMST_ID, OrgSTS_ID, BookingType, month(orgstartdate)
order by Month
 
Any help would be great!
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , For all the group bys you need to have columns in table, that will be added to the visual for the grouping.

With this new column 

Month = month([orgstartdate])

 

 

You need measures for aggregated values

Most of measure will created like this with appropriate aggregation

BaseRevenue =
calculate(Sum(PasF_BookingJourney[RevenueAll]), filter(PasF_BookingJourney, [AGMST_CUSMST_ID] = "525775" && [regdate] <= Date(2020,03,01) && [OrgSTARTDATE] >= date(2020,03,01)
&& ([CANXDATE] >= date(2020,03,01) || isblank([CANXDATE]))))

 

 

This will be bit different
Legs =
calculate(countows(summarize(PasF_BookingJourney,[ID],[OrgSTARTDATE])), filter(PasF_BookingJourney, [AGMST_CUSMST_ID] = "525775" && [regdate] <= Date(2020,03,01) && [OrgSTARTDATE] >= date(2020,03,01)
&& ([CANXDATE] >= date(2020,03,01) || isblank([CANXDATE]))))

 

 

 

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , For all the group bys you need to have columns in table, that will be added to the visual for the grouping.

With this new column 

Month = month([orgstartdate])

 

 

You need measures for aggregated values

Most of measure will created like this with appropriate aggregation

BaseRevenue =
calculate(Sum(PasF_BookingJourney[RevenueAll]), filter(PasF_BookingJourney, [AGMST_CUSMST_ID] = "525775" && [regdate] <= Date(2020,03,01) && [OrgSTARTDATE] >= date(2020,03,01)
&& ([CANXDATE] >= date(2020,03,01) || isblank([CANXDATE]))))

 

 

This will be bit different
Legs =
calculate(countows(summarize(PasF_BookingJourney,[ID],[OrgSTARTDATE])), filter(PasF_BookingJourney, [AGMST_CUSMST_ID] = "525775" && [regdate] <= Date(2020,03,01) && [OrgSTARTDATE] >= date(2020,03,01)
&& ([CANXDATE] >= date(2020,03,01) || isblank([CANXDATE]))))

 

 

 

Anonymous
Not applicable

Thank you @amitchandak  Exactly what I needed. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors