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

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
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.