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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
SebaSpotti
Advocate II
Advocate II

Empty selectvalue eve if is not empty

Hi guys!

I have this calculate table: 

Last12Month = 
VAR ___Date = SELECTEDVALUE(MonthDate[Month])
VAR ___StartDate = DATE(YEAR(___Date),MONTH(___Date),1)
//VAR ___StartDate = TODAY()
VAR DateTable =
    ADDCOLUMNS(
        CALENDAR(___StartDate-365,___StartDate),
        "MonthEnd", EOMONTH([Date],0),
        "MonthStart", DATE(YEAR([Date]),MONTH([Date]),1)
    )
VAR ResultTable =
SUMMARIZE(
    DateTable,
    [MonthEnd],
    "NTR Rolling",
    VAR auxDate = [MonthEnd]
    VAR CurrentDate = EOMONTH(auxDate, 0)
    VAR FilteredTable = 
        CALCULATE(
            SUM(SS_NTR_BY_DAY[Conteggio CMs]),
            FILTER(
                SS_NTR_BY_DAY,
                SS_NTR_BY_DAY[STATUS_START_DATE] > (CurrentDate - 365) &&
                SS_NTR_BY_DAY[STATUS_START_DATE] <= CurrentDate
            )
        )
    RETURN FilteredTable,
    "HC Rolling AVG",
    VAR auxDateHC = [MonthEnd]
    VAR CurrentDateHC = DATE(YEAR(auxDateHC), MONTH(auxDateHC), 1)
    VAR HC = 
        CALCULATE(
            SUM(SS_HC_BY_DAY[Conteggio CMS]) / 365,
            FILTER(
                SS_HC_BY_DAY,
                SS_HC_BY_DAY[COMP_DATE] > (CurrentDateHC - 365) &&
                SS_HC_BY_DAY[COMP_DATE] <= CurrentDateHC
            )
        )
    RETURN HC,
    "Rolling Turnover",
    VAR auxDate = [MonthEnd]
    VAR CurrentDate = EOMONTH(auxDate, 0)
    VAR NTRRolling = 
        CALCULATE(
            SUM(SS_NTR_BY_DAY[Conteggio CMs]),
            FILTER(
                SS_NTR_BY_DAY,
                SS_NTR_BY_DAY[STATUS_START_DATE] > (CurrentDate - 365) &&
                SS_NTR_BY_DAY[STATUS_START_DATE] <= CurrentDate
            )
        )
    VAR auxDateHC = [MonthEnd]
    VAR CurrentDateHC = DATE(YEAR(auxDateHC), MONTH(auxDateHC), 1)    
    VAR HCRollingAVG = 
        CALCULATE(
            SUM(SS_HC_BY_DAY[Conteggio CMS]) / 365,
            FILTER(
                SS_HC_BY_DAY,
                SS_HC_BY_DAY[COMP_DATE] > (CurrentDateHC - 365) &&
                SS_HC_BY_DAY[COMP_DATE] <= CurrentDateHC
            )
        )
    RETURN DIVIDE(NTRRolling, HCRollingAVG)

)

RETURN ResultTable

I got an error, that the SELECTEDVALUE is empty. But if I isolate that measure, is not so.

Any suggestion how to solve this problem?

 

Thanks all! 

1 ACCEPTED SOLUTION
dk_dk
Super User
Super User

Hi @SebaSpotti 

Calculated tables are evaluated with data refresh, so SELECTEDVALUE will not work this way. (I assume your intention was that when you change the slicer selection for Month, the calculated table recalculates with that month, which is not possible)

See these previous threads for proposed workarounds:

https://community.fabric.microsoft.com/t5/Desktop/Calculated-Table-using-SELECTEDVALUE/m-p/911501
https://community.fabric.microsoft.com/t5/Desktop/Using-SELECTEDVALUE-with-Calculated-Table-workarou...





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
Bibiano_Geraldo
Super User
Super User

Hi @SebaSpotti ,

The issue with your code arises because SELECTEDVALUE(MonthDate[Month]) is returning blank in the context where the calculated table is being evaluated. This happens because a calculated table is evaluated in a global context, not in the context of a specific row or filter.

Take off SELECTEDVALUE function and keep only something like this:

VAR ___Date = MonthDate[Month]

 

If this help you, please consider to accept this reply as solution and give a Kudo.

 

thannk you

dk_dk
Super User
Super User

Hi @SebaSpotti 

Calculated tables are evaluated with data refresh, so SELECTEDVALUE will not work this way. (I assume your intention was that when you change the slicer selection for Month, the calculated table recalculates with that month, which is not possible)

See these previous threads for proposed workarounds:

https://community.fabric.microsoft.com/t5/Desktop/Calculated-Table-using-SELECTEDVALUE/m-p/911501
https://community.fabric.microsoft.com/t5/Desktop/Using-SELECTEDVALUE-with-Calculated-Table-workarou...





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors