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

how to write dax query based on sql query?

Hi Team,

 

how to write below sql query in dax expression?

 

select title, hours  from table where title like '%gold%' or title like '%silver%'

 

we need to find calcualte hours based on gold or silver?

 

can you please assist?

 

Thanks

Kunuthuri

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

Please refer to:

Table =
VAR temptab =
    FILTER (
        ADDCOLUMNS (
            Table5,
            "Type", IF (
                ISERROR ( FIND ( "Gold", Table5[Title] ) ) = FALSE (),
                "Gold",
                IF (
                    ISERROR ( FIND ( "Silver", Table5[Title] ) ) = FALSE (),
                    "Silver",
                    BLANK ()
                )
            )
        ),
        [Type] <> BLANK ()
    )
RETURN
    GROUPBY ( temptab, [Type], "Total Hours", SUMX ( CURRENTGROUP (), [Hours] ) )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

4 REPLIES 4
PattemManohar
Community Champion
Community Champion

@Anonymous As there is no sample data, here is the sample data I assumed...

 

image.png

 

Now create a "New Column" as below:

 

TitleNew = SWITCH(TRUE(),
                    SEARCH("Gold",[Title],1,-1)>0,"Gold",
                    SEARCH("Silver",[Title],1,-1)>0,"Silver",
                    "Other")

 

The table now looks like...

 

image.png

 

Now create a "New Table" in required format with total hours...

 

GoldSilverHours = SUMMARIZECOLUMNS(SearchText[TitleNew],"TotalHours",SUM(SearchText[Hours]))

 

So fiinally, the output looks like...

 

image.png

 

Hope this helps !!





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Anonymous
Not applicable

Thanks for reply

 

can you please help below requirement .

 

1. I need to find only Gold and silver records, not others records.

2.  Total Hours for(gold and silver) / Hours

 

Thanks

Kunuthuri

Hi @Anonymous,

 

Please refer to:

Table =
VAR temptab =
    FILTER (
        ADDCOLUMNS (
            Table5,
            "Type", IF (
                ISERROR ( FIND ( "Gold", Table5[Title] ) ) = FALSE (),
                "Gold",
                IF (
                    ISERROR ( FIND ( "Silver", Table5[Title] ) ) = FALSE (),
                    "Silver",
                    BLANK ()
                )
            )
        ),
        [Type] <> BLANK ()
    )
RETURN
    GROUPBY ( temptab, [Type], "Total Hours", SUMX ( CURRENTGROUP (), [Hours] ) )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks for reply

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.