Forum Discussion

mansiluthra12's avatar
4 years ago
Solved

The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

I am trying to add a column, something like below 
total =
ADDCOLUMNS ( VALUES ( Work[Date] ), "Day", CALCULATE(
DISTINCTCOUNT(Work[ID]),
Work[Day] = 1 ,
Test[testValue] = "abc") )
 
but is giving me The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
what's the issue with the syntax
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi mansiluthra12 ,

     

    Your syntax will return a Table not a Column.

     

    So you may try:

    Column1 = CALCULATE(DISTINCTCOUNT('Work'[ID]),FILTER('Work',[Day]=1))
    Column2 = CALCULATE(DISTINCTCOUNT('Work'[ID]),ALLEXCEPT('Work','Work'[Date]),'Work'[Day]=1) 

    Below is the final output:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • mansiluthra12 

    You add a column, the result of your formula is supposed to produce one value, On which table are you adding column? May you need to get the maximum of the result as follows. Please check: Share the screenshot of your table and the new column

    total =
    MAXX (
        ADDCOLUMNS (
            VALUES ( Work[Date] ),
            "Day",
                CALCULATE ( DISTINCTCOUNT ( Work[ID] ), Work[Day] = 1, Test[testValue] = "abc" )
        ),
        [Day]
    )
    

     

  • Hi mansiluthra12 ,

     

    I think you need a FILTER expression within your CALCULATE function.

    total =
        ADDCOLUMNS ( VALUES ( Work[Date] ), "Day", 
                     CALCULATE(
                               DISTINCTCOUNT(Work[ID]),
                               FILTER(Work, Work[Day] = 1) ,
                               FILTER(Test[testValue] = "abc") 
                              )
                   )

    I haven't tested the DAX, just re-wrote it.

     

    Thanks,

    Pragati

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi mansiluthra12 ,

     

    Your syntax will return a Table not a Column.

     

    So you may try:

    Column1 = CALCULATE(DISTINCTCOUNT('Work'[ID]),FILTER('Work',[Day]=1))
    Column2 = CALCULATE(DISTINCTCOUNT('Work'[ID]),ALLEXCEPT('Work','Work'[Date]),'Work'[Day]=1) 

    Below is the final output:

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.