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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Getting different data based on a Range column.

Hi All, I have some issue regarding getting different set of data by using date measure. 

 

ameng_0-1658806202644.png

This is the PBI file that i'm working on. 

Based on above figure, this is the range, and the data produced by that range but that's not aligned with what i should get. What i should get is  an output something like this

ameng_4-1658805228954.png

for example, on the "selectedDate" range slicer, i'm choosing 24 February 2018, the result for year 2017 should be in the selected date of 24 February 2017 and for year 2016, it should be in the selected of 24 February 2016. I'm not sure what measure should i change and how to proceed. The data for "no of orders by selected month" should be just the total count of those in Jan and Feb in every year only based on below table.

ameng_0-1658805971898.png


List of Measures used-

No of Orders by Selected Month =
VAR _selectedmonthselecteddate = [test]
RETURN CALCULATE([Order Count], 'Calendar'[MonthNum] <= _selectedmonthselecteddate)
 
test = CALCULATE(MAX('Calendar'[MonthNum]), Filter('Calendar',[MonthNum] = Month(_Formulas[SelectedDate])))

 

SelectedDate =
Var _SelectedDate = Max('Calendar'[Date])
Return _SelectedDate

This is the PBI file that i'm working on. Hope you all have a nice day ahead, thank you!!
@amitchandak

 

 

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous,

 

You may try this solution.

1 Modify your Selected Date as follows

SelectedDate =
VAR _SelectedDate =
    MAX ( 'Calendar'[Date] )
VAR maxDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
RETURN
    DATE ( YEAR ( _SelectedDate ), MONTH ( maxDate ), DAY ( maxDate ) )

 

2 Create another Measure

OrdersBySelectedMonth =
VAR selectedMaxDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
RETURN
    CALCULATE (
        [Order Count],
        FILTER ( 'Calendar', MONTH ( 'Calendar'[Date] ) <= MONTH ( selectedMaxDate ) )
    )

 

The result looks like this.

vcazhengmsft_0-1658993163789.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,                                                                                                                                                                    Community Support Team _ Caiyun

View solution in original post

3 REPLIES 3
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous,

 

You may try this solution.

1 Modify your Selected Date as follows

SelectedDate =
VAR _SelectedDate =
    MAX ( 'Calendar'[Date] )
VAR maxDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
RETURN
    DATE ( YEAR ( _SelectedDate ), MONTH ( maxDate ), DAY ( maxDate ) )

 

2 Create another Measure

OrdersBySelectedMonth =
VAR selectedMaxDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
RETURN
    CALCULATE (
        [Order Count],
        FILTER ( 'Calendar', MONTH ( 'Calendar'[Date] ) <= MONTH ( selectedMaxDate ) )
    )

 

The result looks like this.

vcazhengmsft_0-1658993163789.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,                                                                                                                                                                    Community Support Team _ Caiyun

tamerj1
Super User
Super User

Hi @Anonymous 
Please refer to sample file with the solution https://we.tl/t-JBXwFiPLen

1.png2.png

Order Count = 
VAR LastSelectedDate = MAXX ( ALLSELECTED ( 'Calendar'[Date] ), 'Calendar'[Date] )
VAR SelectedDay = DAY ( LastSelectedDate )
VAR SelectedMonth = MONTH ( LastSelectedDate ) 
VAR CurrentYear = YEAR ( MAX ( 'Calendar'[Date] ) )
VAR Result =
    CALCULATE (
        DISTINCTCOUNT ( Sales[SalesOrderNumber] ),
        KEEPFILTERS ( 'Calendar'[MonthNum] = SelectedMonth ),
        FILTER ( 'Calendar', DAY ( 'Calendar'[Date] ) =  SelectedDay )
    )
RETURN
    Result
amitchandak
Super User
Super User

@Anonymous ,

For of if you take a joined date table data will merge in one single date

So use an independent date in the slicer

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = format(maxx(allselected(Date1),Date1[Date]), "mmdd")
return
calculate( sum(Table[Value]), filter('Date',format( 'Date'[Date] "mmdd") =_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors