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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
abhishekrws01
Helper I
Helper I

Selectedvalue Function returning Null Values

Hello ,

Please help if possible, I have been trying to solve it for few days now. Its related SelectedValue function. 

 

Context : I have two relational tables i.e. datilyTxdata (fact) and calendar table. I am trying to create a calculated table and would like to add a column within this table.

 

Calculated Table 1
Dailyreport = 
VAR DateLevelSummaryTable =
SUMMARIZE(DailyTxData,DailyTxData[BRAND],Region[Display Country Name],Region[Sort Key],DailyTxData[MARKET], DailyTxData[ISSUEDATE],'Calendar'[Week End Date],DailyTxData[TRAFFICTYPE],DailyTxData[GEO_NAME],"WD at Day Level",MAX(DailyTxData[Weekdays]) , "Gross TX" , SUM(DailyTxData[GROSS_TRANSACTION]) , "Net TX" , SUM(DailyTxData[NET_TRANSACTION]),"Net Sales", SUM(DailyTxData[NET_SALES]) )

Return
DateLevelSummaryTable  - This works fine
 
Then I have a date slice :  Slicer Select Date = SELECTEDVALUE('Calendar'[Date]) . This works fine when I visualize it
abhishekrws01_0-1677702997668.png

 

but doesn't work when I use it for column creation.
 
Here is where I need help please:
 
Calculated Table 2
Dailyreport2 =
Var statedate = CALCULATE([Slicer Select Date])
VAR A =
    ADDCOLUMNS(Dailyreport,"ReportingWeek" , DATEDIFF(Dailyreport[ISSUEDATE], statedate,DAY ), "Grouping" , If(DATEDIFF(Dailyreport[ISSUEDATE], statedate,DAY )<7 , "L7" , "XX"))

Return
A
 I get blank value in the table for "ReportingWeek". 
 
Hope this makes sense. 
Thank you for your help in advance.
 
 
 
1 ACCEPTED SOLUTION

Hi @abhishekrws01 ,

 

I made a simple sample for your reference.

Sample data:

vstephenmsft_0-1679380286444.png

Given that the dates in this sample are incomplete. Incomplete dates are not convenient for slicer filtering. Let's create a calendar table for the slicer.

Table 2 = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

vstephenmsft_1-1679380371695.png

There's no relationship between tables.

vstephenmsft_2-1679380394575.png

Create a measure to get the sum of sales for the last 6 weeks based on the selected date.

Sales for last 6 weeks =
VAR _sel =
    SELECTEDVALUE ( 'Table 2'[Date] )
VAR _date = _sel - 42
RETURN
    CALCULATE (
        SUM ( 'Table'[Sale] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Date] >= _date && [Date] <= _sel )
    )

When you select a date from the slicer, the measure returns the result.

vstephenmsft_3-1679380830651.png

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

 

 

View solution in original post

3 REPLIES 3
HotChilli
Super User
Super User

Slicers cannot affect calculated columns or tables.

Slicers are for visuals and measures.

Hi - Thank you for your response. Can you or anyone in the community please suggest some way how I can achieve this? I am trying to dynamically calculate sales, working days and a few other KPIs for the last 6 weeks. In the example below, the selected date is 30-Jan-2023. If the user selects another day, then these dates will move accordingly.  Can I use Parameter or separate table etc?  

abhishekrws01_0-1677748954841.png

Thank you for your help in advance.

Hi @abhishekrws01 ,

 

I made a simple sample for your reference.

Sample data:

vstephenmsft_0-1679380286444.png

Given that the dates in this sample are incomplete. Incomplete dates are not convenient for slicer filtering. Let's create a calendar table for the slicer.

Table 2 = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

vstephenmsft_1-1679380371695.png

There's no relationship between tables.

vstephenmsft_2-1679380394575.png

Create a measure to get the sum of sales for the last 6 weeks based on the selected date.

Sales for last 6 weeks =
VAR _sel =
    SELECTEDVALUE ( 'Table 2'[Date] )
VAR _date = _sel - 42
RETURN
    CALCULATE (
        SUM ( 'Table'[Sale] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Date] >= _date && [Date] <= _sel )
    )

When you select a date from the slicer, the measure returns the result.

vstephenmsft_3-1679380830651.png

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.