简体   繁体   中英

Converting from SQL into Power BI

I am trying to convert this from SQL into a Power BI measure but receive no value after running the measure. This is the SQL code:

sum(case when(tbl.Category = '' and (tbl.Name like 'N%' or tbl.Name like 'S%' or tbl.Name like 'T%')) then tbl.Weight/2000 else 0 end)
    as 'Total Tons'

This is what I tried in Power BI. Is it an issue of the wildcard (does PowerBI recognize the % as include whatever after starting with T,S, or N)?

TonsMeasure = 
CALCULATE(
    [Totaltons/2000],
    tbl[Category] = "", 
    tbl[Name] = "N%", 
    tbl[Name] = "T%", 
    tbl[Name] = "S%"
)

你可以试试下面的

Measure = sumx(t, switch( true, (left(t[name],1)="N" || left(t[name],1)="S" || left(t[name],1)="T") &&  t[cat]=" ",  divide (t[weight],2000)))

If you are looking for new column per row based on other values in the row, you can try this below measure-

TonsMeasure = 
IF(
    min(tbl[Category]) = ""
    && (
        LEFT(min(tbl[Name]),1) = "N" ||
        LEFT(min(tbl[Name]),1) = "T" ||
        LEFT(min(tbl[Name]),1) = "S"
    ),
    min(tbl.Weight)/2000,
    0
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM