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
MarkEden
Frequent Visitor

TopN using offsets error

Hi All,

 

I'm  fairly new to DAX and struggling with something that seems like it should be fairly simple.

 

I'm trying to create a TopN measure to use as a filter with the month offset column in my date table and visualise the most recent N months from the selected value. This is the fomula I've written but it only returns the value for the selected month (ie Top 1) instead of the top 12. 

 

I'd appreciate any advice on where I've gone wrong here. I'm trying to return top 12 values not rows.

 

TopN = 
var maxdate = MAX('Date Table'[MonthOffset])
RETURN
TOPN( 12,
CALCULATETABLE( 
    VALUES('Date Table'[MonthOffset]),
    'Date Table'[MonthOffset] <= maxdate),
     'Date Table'[MonthOffset],
     DESC
)

  

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your data model looks like, but please try below whether it suits your requirement.

 

TopN =
VAR maxdate =
    MAX ( 'Date Table'[MonthOffset] )
RETURN
    TOPN (
        12,
        FILTER (
            ALL ( 'Date Table'[MonthOffset] ),
            'Date Table'[MonthOffset] <= maxdate
        ),
        'Date Table'[MonthOffset], DESC
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

@Jihwan_Kim thank you. I think I'm close but am getting the error "a table of multiple values was supplied where a single value was expected".

I thought this might be because multiple dates in a month will have the same month offset, so created and tried a day offset but this gave the same result.

So you know how this might be modified to work correctly?

 

@tamerj1 - As requested the below screen shot is the visual I am trying to filter. Currently this shows a period to the beginning of the data, but I want to filter it to the last 12 months only based on the selected month & year. I think I need to use offset columns to do this as filtering the visual based on dates doesn't seem to work. So I think I need to create a measure that returns true if the date is within 12 months of the selected and then use that as a filter on the visual, but open to other suggestions from more knowledgable users.

 

MarkEden_0-1663552060884.png

My TopN measure as it is returns true only the selected month and year. Here June 2022 is selected:

MarkEden_1-1663552155215.png

I have a data model with a one to may relationship from my date table to my fact table, with year, month and day offset columns in the date table.

 

Hope this clarifies what I'm trying to do, but please let me know if any other queries.

 

Thanks in advance

 

 

 

 

tamerj1
Super User
Super User

Hi @MarkEden 

would you please explain in more details what are you trying to achieve perhaps with some screenshots. Your Topn measure returns a table! Are trying to create a calculated table?

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.