Forum Discussion

Saxon10's avatar
Saxon10
Icon for Post Prodigy rankPost Prodigy
5 years ago
Solved

Countifs and search with left in Power BI

  I have a two tables are Data and Report. In Data and Report table contain the following columns are Item and area code. In data table the item and area code contain prefix and suffix or prefix o...
  • Anonymous's avatar
    Anonymous
    5 years ago

    I am not sure that I properly understood your requirement about how you are matching between these two tables. But based on what I have understood, I have written the DAX code for the two calculated columns which are given below..

     

    Try it in your PBIX and let me know if you need any changes. Considering that you have written a complicated formula in Excel, I am sure that you will be able to modify it to your requirements.

     

    Desired Result 1 = 
    VAR CurItem = LEFT(REPORT[ITEM],SEARCH("-",REPORT[ITEM],1,LEN(REPORT[ITEM])+1)-1)
    VAR CurArea = LEFT(REPORT[AREA CODE],SEARCH("-",REPORT[AREA CODE],1,LEN(REPORT[AREA CODE])+1)-1)
    VAR CheckInData = 
        COUNTROWS(
            FILTER(
                DATA,
                DATA[AREA CODE]=CurArea &&
                NOT(ISBLANK(SEARCH(CurItem,DATA[PART NUMBERS],1,BLANK())))
            )
        )
    VAR Result = IF(ISBLANK(CheckInData),"NO",CurArea)
    RETURN
    Result

     

    Desired Result YesNo = 
    VAR CurItem = LEFT(REPORT[ITEM],SEARCH("-",REPORT[ITEM],1,LEN(REPORT[ITEM])+1)-1)
    VAR CurArea = LEFT(REPORT[AREA CODE],SEARCH("-",REPORT[AREA CODE],1,LEN(REPORT[AREA CODE])+1)-1)
    VAR CheckInData = 
        COUNTROWS(
            FILTER(
                DATA,
                DATA[AREA CODE]=CurArea &&
                NOT(ISBLANK(SEARCH(CurItem,DATA[PART NUMBERS],1,BLANK())))
            )
        )
    VAR Result = IF(ISBLANK(CheckInData),"No","Yes")
    RETURN
    Result