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
RJ_KON
Helper I
Helper I

DAX using Selected value function

Hi, I am developing  week on week, month to date and Year to date financial Power bi report.

 

Below is the scenario that I am trying to develop

- Provided financial week, financial period and year slicer

- When user select a current week in slicer my matrix table categorised by product should show sales income for selected week and previous week, I acheived this by using below Dax queries

SelectedWeek =
VAR Selectedweeknumber=SELECTEDVALUE('Dim_Calendar MT'[Financial Week])
RETURN
CALCULATE([VNI],
FILTER(ALL('Dim_Calendar MT'),'Dim_Calendar MT'[Financial Week]=Selectedweeknumber))
Previous week
SelectedWeek(PW) =
CALCULATE([VNI],
FILTER(ALL('Dim_Calendar MT'),'Dim_Calendar MT'[WeekRank]=SELECTEDVALUE('Dim_Calendar MT'[WeekRank])-1))
 
I am struggling to achieve  values for previous month  , for example
when user selected current Feb month with two weeks completed and I want to obtain previous month only two weeks data not full month. Bekow are my queries
SelectedMonth =
VAR SelectedPeriod=SELECTEDVALUE('Dim_Calendar MT'[Financial Period])
RETURN
CALCULATE([VNI],
FILTER(ALL('Dim_Calendar MT'),'Dim_Calendar MT'[Financial Period]=SelectedPeriod))
 
PreviousMonth=
CALCULATE([VNI],
FILTER(ALL('Dim_Calendar MT'),'Dim_Calendar MT'[PeriodRank]=SELECTEDVALUE('Dim_Calendar MT'[PeriodRank])-1))
 
need help with getting previous month value up to certain weeks using selected value function
 
Regards
RJ_KON
1 ACCEPTED SOLUTION

Hi @v-yiruan-msft

       As requested, attached are some images of the data. 

Below are the results I am expecting

  • My matrix table got two columns one column displays the sales of the selected month and another column should display the previous month sales
  • Now we are in period 11 and the selected month displays sales up to week 47, so cumulative sales include W45, W46, and W47 sales in the selected month.
  • In the previous month, I mean period 10 I would like to display only three weeks' data.
  • If the user selects Period 10, he should see sales for all weeks in the selected month period 10 and another column should show all weeks from period 9

Please see below attached screenshots of visual data.

 

Matrix table with two columns, one is current month (CM) and another column Previous month (PM)Matrix table with two columns, one is current month (CM) and another column Previous month (PM)

 

Month slicerMonth slicer

 

View solution in original post

4 REPLIES 4
v-yiruan-msft
Community Support
Community Support

Hi @RJ_KON ,

You can update the formula of measure [PreviousMonth] as below and check if it can return your expected result...

PreviousMonth =
VAR _periodrank =
    SELECTEDVALUE ( 'Dim_Calendar MT'[PeriodRank] )
VAR _weekrank =
    CALCULATE (
        MIN ( 'Dim_Calendar MT'[WeekRank] ),
        FILTER (
            ALL ( 'Dim_Calendar MT' ),
            'Dim_Calendar MT'[PeriodRank] = _periodrank
        )
    )
RETURN
    CALCULATE (
        [VNI],
        FILTER (
            ALL ( 'Dim_Calendar MT' ),
            'Dim_Calendar MT'[PeriodRank] = _periodrank - 1
                && 'Dim_Calendar MT'[WeekRank] >= _weekrank - 2
                && 'Dim_Calendar MT'[WeekRank] <= _weekrank - 1
        )
    )

 

If the above one is not working, could you please provide some raw data in your fact table and the table 'Dim_Calendar MT' (exclude sensitive data) with Text format and your expected result with backend logic and special examples? By the way, is there any relationship between your fact table and the table 'Dim_Calendar MT'? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

@v-yiruan-msft,

 

Thanks for the formulae, but from period slicer when user select period 10, so for  previous week which is period 9 it is returning only two weeks value according to the above formulae, but I would like to see full period 9 weeks value. 

 

RJ_KON

Hi @RJ_KON ,

What's your final expected result? When user select period 10, the visual need to display the data which the period is 9? Could you please provide some sample data and special example to explain your expected result? Thank you.

Best Regards

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

Hi @v-yiruan-msft

       As requested, attached are some images of the data. 

Below are the results I am expecting

  • My matrix table got two columns one column displays the sales of the selected month and another column should display the previous month sales
  • Now we are in period 11 and the selected month displays sales up to week 47, so cumulative sales include W45, W46, and W47 sales in the selected month.
  • In the previous month, I mean period 10 I would like to display only three weeks' data.
  • If the user selects Period 10, he should see sales for all weeks in the selected month period 10 and another column should show all weeks from period 9

Please see below attached screenshots of visual data.

 

Matrix table with two columns, one is current month (CM) and another column Previous month (PM)Matrix table with two columns, one is current month (CM) and another column Previous month (PM)

 

Month slicerMonth slicer

 

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.