Forum Discussion

sminonese's avatar
sminonese
Frequent Visitor
9 years ago
Solved

Query comparing continuous variables

Hi,   I am looking for a tip on how to solve this. As far as I can tell I will need some DAX magic.   I have two tables: Samples and Quality.   Samples have a unique ID field and two numeric fi...
  • Anonymous's avatar
    Anonymous
    9 years ago

    Hi sminonese,

     

    You can refer to bleow steps if it suitable for your requirement:

     

    1. Use "SELECTCOLUMNS" and "CONCATENATEX" function to add the quality tag.

    Summary Table = SELECTCOLUMNS('Sample',"SampleID",[SampleID],"Quality",CONCATENATEX(FILTER(ALL('Quality Specifications'),[Quant1]>=[Quant1_Low]&&[Quant1]<=[Quant1_high]&&[Quant2]>=[Quant2_Low]&&[Quant2]<=[Quant2_high]),[Quality],","))

     

     

    2. Use variable to store above table and use SUBSTITUTE function to convert "Quality" column to new columns.

    Summary Table = 
    var temp=SELECTCOLUMNS('Sample',"SampleID",[SampleID],"Quality",CONCATENATEX(FILTER(ALL('Quality Specifications'),[Quant1]>=[Quant1_Low]&&[Quant1]<=[Quant1_high]&&[Quant2]>=[Quant2_Low]&&[Quant2]<=[Quant2_high]),[Quality],","))
    return
        SELECTCOLUMNS(temp,"SampleID",[SampleID],"LEFT", LEFT(SUBSTITUTE([Quality],",","-"),SEARCH("-",SUBSTITUTE([Quality],",","-"))-1),"RIGHT",RIGHT(SUBSTITUTE([Quality],",","-"),LEN(SUBSTITUTE([Quality],",","-"))-SEARCH("-",SUBSTITUTE([Quality],",","-"))))

     

    3. Use SELECTCOLUMNS and UNION function to merge left and right part.

    Summary Table = 
    var temp=SELECTCOLUMNS('Sample',"SampleID",[SampleID],"Quality",CONCATENATEX(FILTER(ALL('Quality Specifications'),[Quant1]>=[Quant1_Low]&&[Quant1]<=[Quant1_high]&&[Quant2]>=[Quant2_Low]&&[Quant2]<=[Quant2_high]),[Quality],","))
    return
    UNION(
        SELECTCOLUMNS(temp,"SampleID",[SampleID],"Quality", LEFT(SUBSTITUTE([Quality],",","-"),SEARCH("-",SUBSTITUTE([Quality],",","-"))-1)),
        SELECTCOLUMNS(temp,"SampleID",[SampleID],"Quality",RIGHT(SUBSTITUTE([Quality],",","-"),LEN(SUBSTITUTE([Quality],",","-"))-SEARCH("-",SUBSTITUTE([Quality],",","-"))))
      )

     

     

    Regards,

    Xiaoxin Sheng