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
Anonymous
Not applicable

SQL to DAX

Hello All, 

 

I need some help in converting the following SQL query into a DAX measure 

 

select [Booking Reference], [Sailing ID], [Sailing Date], [Category ID], c.[Category Group], Quantity, [Category Price], [Booking Currency Price]

from vw_PasF_BookingJourney bf

join vw_PasD_Category c on bf.[Category ID] = c.[Actual Category]

where [Booking Reference] = '21394547'

 

Thanks in advance!

 

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Based on your description, I have create two sample tables in sql and in power bi desktop:

q1.pngq2.png

The sql query would result this result:

q3.png

 

To get the same result table in power bi, you can create this caculated table:

Result table =
ADDCOLUMNS (
    FILTER (
        ALL ( 'BF' ),
        'BF'[Booking Reference] = "21394547"
            && 'BF'[Category ID] IN DISTINCT ( 'C'[Actual Category] )
    ),
    "Category Group",
        MAXX (
            FILTER ( 'C', 'C'[Actual Category] = 'BF'[Category ID] ),
            [Category Group]
        )
)

tb.png

 

Attached the sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Based on your description, I have create two sample tables in sql and in power bi desktop:

q1.pngq2.png

The sql query would result this result:

q3.png

 

To get the same result table in power bi, you can create this caculated table:

Result table =
ADDCOLUMNS (
    FILTER (
        ALL ( 'BF' ),
        'BF'[Booking Reference] = "21394547"
            && 'BF'[Category ID] IN DISTINCT ( 'C'[Actual Category] )
    ),
    "Category Group",
        MAXX (
            FILTER ( 'C', 'C'[Actual Category] = 'BF'[Category ID] ),
            [Category Group]
        )
)

tb.png

 

Attached the sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @v-yingjl ,

 

Thanks for the explanation. However, I am getting the following error when I try to create the calculated table. 

Kartiklal03_0-1618996297600.png

 

Hi @Anonymous ,

Seems like your data type of [Booking Reference] is number type not text type while my sample file is the text type. You can modify it like this:

 'BF'[Booking Reference] = 21394547

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@Hi @v-yingjl , 

 

Thank you! Exactly what I wanted. 

amitchandak
Super User
Super User

@Anonymous , In power bi , you need join two tables on vw_PasF_BookingJourney  vw_PasD_Category  using

[Category ID] and [Actual Category],

 

On slicer you can take filter of [Booking Reference] = "21394547"

 

Or add this measure with all un summarized columns

 

calculate(countrows(vw_PasF_BookingJourney ), filter(vw_PasD_Category , vw_PasD_Category[Booking Reference] = "21394547"))

 

refer my series DAX vs SQL -https://www.youtube.com/watch?v=WlvQ_SGy4iA&list=PLPaNVDMhUXGZNyKU0PgG2g3P0c6CPjMnj

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.