Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ranjanrkl127
New Member

Need help in resolving DAX Query Issues

This is my DAX Query and It fails with the error below, the column [Modelling Types] has multiple values, any quick help in resolving this?

A single value for column 'Modelling Types' in table 'Modelling Types' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

IF (
    SELECTEDVALUE ( 'Modelling Types'[Modelling Types] ) = "Multiply using Leases Tracking Rate"
        || SELECTEDVALUE ( 'Modelling Types'[Modelling Types] ) = "Multiply using Village Tracking Rate",
    SUMX (
        VAR SummarizedTable =
            IF (
                'Modelling Types'[Modelling Types] = "Multiply using Leases Tracking Rate",
                SUMMARIZE ( 'Tracked Sales', Dates[Date], Leases[FactLease Key] ),
                SUMMARIZE ( 'Tracked Sales', Dates[Date], Villages[Village Key] )
            )
        RETURN
            ADDCOLUMNS (
                SummarizedTable,
                "Tracking Rate", IF (
                    'Modelling Types'[Modelling Types] = "Multiply using Leases Tracking Rate",
                    CALCULATE (
                        [% Tracked Sales vs Total Sales],
                        ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Leases' )
                    ),
                    CALCULATE (
                        [% Tracked Sales vs Total Sales],
                        ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Villages' )
                    )
                ),
                "selectedmeasure", [TrackedSalesNetBase]
            ),
        VAR MultiplicationFactor =
            DIVIDE ( 1, [Tracking Rate] )
        RETURN
            [selectedmeasure] * MultiplicationFactor
    ),
    [TrackedSalesNetBase]
)

 

10 REPLIES 10
AntrikshSharma
Super User
Super User

@ranjanrkl127 Use variables so that you can check intermediate steps by replacing the Result variable at the end.

 

=
VAR ModelType =
    SELECTEDVALUE ( 'Modelling Types'[Modelling Types] )
VAR IsModelTypeLeases = ModelType = "Multiply using Leases Tracking Rate"
VAR IsModelTypeVillage = ModelType = "Multiply using Village Tracking Rate"
VAR SummarizedTable =
    IF (
        IsModelTypeLeases,
        SUMMARIZE ( 'Tracked Sales', Dates[Date], Leases[FactLease Key] ),
        SUMMARIZE ( 'Tracked Sales', Dates[Date], Villages[Village Key] )
    )
VAR IntermediateTable =
    ADDCOLUMNS (
        SummarizedTable,
        "Tracking Rate", IF (
            IsModelTypeLeases,
            CALCULATE (
                [% Tracked Sales vs Total Sales],
                ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Leases' )
            ),
            CALCULATE (
                [% Tracked Sales vs Total Sales],
                ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Villages' )
            )
        ),
        "selectedmeasure", [TrackedSalesNetBase]
    )
VAR PreResult =
    SUMX (
        IntermediateTable,
        VAR MultiplicationFactor =
            DIVIDE ( 1, [Tracking Rate] )
        RETURN
            [selectedmeasure] * MultiplicationFactor
    )
VAR Result =
    IF ( IsModelTypeLeases || IsModelTypeVillage, PreResult, [TrackedSalesNetBase] )
RETURN
    Result

 

Thanks 

I tried the code with variable, but deployment still fails with the error:

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

 

 

VAR ModelType =
    SELECTEDVALUE ( 'Modelling Types'[Modelling Types] )
VAR IsModelTypeLeases = ModelType = "Multiply using Leases Tracking Rate"
VAR IsModelTypeVillage = ModelType = "Multiply using Village Tracking Rate"
VAR SummarizedTable =
    IF (
        IsModelTypeLeases,
        SUMMARIZE ( 'Tracked Sales', Dates[Date], Leases[FactLease Key] ),
        SUMMARIZE ( 'Tracked Sales', Dates[Date], Villages[Village Key] )
    )
VAR IntermediateTable =
    ADDCOLUMNS (
        SummarizedTable,
        "Tracking Rate", IF (
            IsModelTypeLeases,
            CALCULATE (
                [% Tracked Sales vs Total Sales],
                ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Leases' )
            ),
            CALCULATE (
                [% Tracked Sales vs Total Sales],
                ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Villages' )
            )
        ),
        "selectedmeasure", [TrackedSalesNetBase]
    )
VAR PreResult =
    SUMX (
        IntermediateTable,
        VAR MultiplicationFactor =
            DIVIDE ( 1, [Tracking Rate] )
        RETURN
            [selectedmeasure] * MultiplicationFactor
    )
VAR Result =
    IF ( IsModelTypeLeases || IsModelTypeVillage, PreResult, [TrackedSalesNetBase] )
RETURN
    Result

 

 

 

Anonymous
Not applicable

This piece of code will never work:

VAR SummarizedTable =
IF (
IsModelTypeLeases,
SUMMARIZE ( 'Tracked Sales', Dates[Date], Leases[FactLease Key] ),
SUMMARIZE ( 'Tracked Sales', Dates[Date], Villages[Village Key] )
)

You CANNOT return a table from IF.

@ranjanrkl127  What are the definitions of [TrackedSalesNetBase] and [Tracking Rate] ?

 

Pragati11
Super User
Super User

Hi @ranjanrkl127 ,

 

I think you are creating a MEASURE here. If you try creating a COLUMN using same DAX, you will not get the error.

 

If you still need this as a measure, then use an aggregation function around your Model Type column like below:

IF (
SELECTEDVALUE ( MAX('Modelling Types'[Modelling Types] )) = "Multiply using Leases Tracking Rate"
|| SELECTEDVALUE ( MAX('Modelling Types'[Modelling Types]) ) = "Multiply using Village Tracking Rate",
SUMX (
VAR SummarizedTable =
IF (
MAX('Modelling Types'[Modelling Types]) = "Multiply using Leases Tracking Rate",
SUMMARIZE ( 'Tracked Sales', Dates[Date], Leases[FactLease Key] ),
SUMMARIZE ( 'Tracked Sales', Dates[Date], Villages[Village Key] )
)
RETURN
ADDCOLUMNS (
SummarizedTable,
"Tracking Rate", IF (
MAX('Modelling Types'[Modelling Types]) = "Multiply using Leases Tracking Rate",
CALCULATE (
[% Tracked Sales vs Total Sales],
ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Leases' )
),
CALCULATE (
[% Tracked Sales vs Total Sales],
ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Villages' )
)
),
"selectedmeasure", [TrackedSalesNetBase]
),
VAR MultiplicationFactor =
DIVIDE ( 1, [Tracking Rate] )
RETURN
[selectedmeasure] * MultiplicationFactor
),
[TrackedSalesNetBase]
)

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Thanks Pragati,

Yes, I am creating a measure, I applied MAX as suggested but deployment failed again with the error: any further suggestion i can try?

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

IF (
    SELECTEDVALUE(MAX( 'Modelling Types'[Modelling Types] )) = "Multiply using Leases Tracking Rate"
        || SELECTEDVALUE(MAX ( 'Modelling Types'[Modelling Types] )) = "Multiply using Village Tracking Rate",
    SUMX (
        VAR SummarizedTable =
            IF (
                MAX('Modelling Types'[Modelling Types]) = "Multiply using Leases Tracking Rate",
                SUMMARIZE ( 'Tracked Sales', Dates[Date], Leases[FactLease Key] ),
                SUMMARIZE ( 'Tracked Sales', Dates[Date], Villages[Village Key] )
            )
        RETURN
            ADDCOLUMNS (
                SummarizedTable,
                "Tracking Rate", IF (
                    MAX ( 'Modelling Types'[Modelling Types] ) = "Multiply using Leases Tracking Rate",
                    CALCULATE (
                        [% Tracked Sales vs Total Sales],
                        ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Leases' )
                    ),
                    CALCULATE (
                        [% Tracked Sales vs Total Sales],
                        ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Villages' )
                    )
                ),
                "selectedmeasure", [TrackedSalesNetBase]
            ),
        VAR MultiplicationFactor =
            DIVIDE ( 1, [Tracking Rate] )
        RETURN
            [selectedmeasure] * MultiplicationFactor
    ),
    [TrackedSalesNetBase]
)



 

Hi @ranjanrkl127 ,

 

Remove SELECTED VALUE clause from your DAX. It should work.

 

IF (
 ( MAX('Modelling Types'[Modelling Types] )) = "Multiply using Leases Tracking Rate"
||  ( MAX('Modelling Types'[Modelling Types]) ) = "Multiply using Village Tracking Rate",
SUMX (
VAR SummarizedTable =
IF (
MAX('Modelling Types'[Modelling Types]) = "Multiply using Leases Tracking Rate",
SUMMARIZE ( 'Tracked Sales', Dates[Date], Leases[FactLease Key] ),
SUMMARIZE ( 'Tracked Sales', Dates[Date], Villages[Village Key] )
)
RETURN
ADDCOLUMNS (
SummarizedTable,
"Tracking Rate", IF (
MAX('Modelling Types'[Modelling Types]) = "Multiply using Leases Tracking Rate",
CALCULATE (
[% Tracked Sales vs Total Sales],
ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Leases' )
),
CALCULATE (
[% Tracked Sales vs Total Sales],
ALLEXCEPT ( 'Tracked Sales', 'Dates', 'Villages' )
)
),
"selectedmeasure", [TrackedSalesNetBase]
),
VAR MultiplicationFactor =
DIVIDE ( 1, [Tracking Rate] )
RETURN
[selectedmeasure] * MultiplicationFactor
),
[TrackedSalesNetBase]
)

 

I can't test the DAX at my end as I don't have data. But yes try the above chnaged dax.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Sure, i will try now but wanted to check if MAX should really be used with String data? as the column has 3 string data and doing a MAX on it doesn't feel right, any thoughts?

Regards,

 

Ranjan

Hi @ranjanrkl127 ,

 

Therefore I mentioned that try creating a column rather than a measure, using your original DAX.

 

Also, try tagging people on your responses, just helps us.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Thanks 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.