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
Anonymous
Not applicable

Prior year calculation not working filtering on measure

So here is my model:

modelmodel

So if I use this query:

DEFINE
    VAR columnFilter0 =
        TREATAS (
            { "**********", "************", "**********" },
            'Distributor'[Parent Distributor]
        )
    VAR columnFilter1 =
        FILTER ( KEEPFILTERS ( VALUES ( 'Time'[Year] ) ), ( 'Time'[Year] = 2019 ) )
    VAR measuresFilter =
        FILTER (
            KEEPFILTERS (
                SUMMARIZECOLUMNS (
                    'Customer'[CDSId],
                    'Distributor'[Parent Distributor],
                    'Time'[Year],
                    columnFilter0,
                    columnFilter1,
                    "Cases", [Cases],
                     "Cases PY", CALCULATE([Cases PY], all('time'[Date]))
                )
            ),
            ( [Cases] < 1000 )
        )
EVALUATE
TOPN (
    200,
    SUMMARIZECOLUMNS (
        ROLLUPADDISSUBTOTAL (
            ROLLUPGROUP (
                'Customer'[CDSId],
                'Distributor'[Parent Distributor],
                'Time'[Year]
            ),
            "total"
        ),
        columnFilter0,
        columnFilter1,
        measuresFilter,
        "Cases", [Cases],
        "Cases PY", CALCULATE(Sum('sale'[OCases]),DATEADD('Time'[Date], -1 ,YEAR))
    ),
    [total], 0
)
ORDER BY [total] DESC

my results look like this:

data Prior yeardata Prior year

I loss my prior year for some reason. If i remove the measure filter it i get prior year back. If I remove distributor i get it back. If i remove distributor and put something form like item table it still does not have prior year. if i remove the customer table fields it goes back to working.

 

I think its something to do with the wired many to many i made when denormlizing my customers but I'm unsure.

 

 

Prior year Clculation

CALCULATE([Cases],SAMEPERIODLASTYEAR('Time'[date]))

 

 

6 REPLIES 6
Greg_Deckler
Super User
Super User

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

I see how to do To Date measures in your post but can't apply really to how i'm trying to calculate py. I need a sum based on the picked time filter and then for py is the picked time filter 1 year prior. so it can span between years 2018-2019

For the date filter, you can use the option given in the article and then calculate you can calculate prior year based on the Min or Max date of the slicer.

Current Sales = ( 
VAR _Cuur_start = Generator[Report Start Date]
VAR _Curr_END = Generator[Report End Date]
return 
calculate(sum(Sales[Sales]),OrderTime[Order Date] >= _Cuur_start && OrderTime[Order Date] <= _Curr_END )
)
Generator in this example is the same date in the article.
With Date Joined with Table
Sales Last Year = CALCULATE(sum(Sales[Sales]),OrderTime[Order Year]= CONCATENATE( Year(NOW())-1,""))
2nd last year = CALCULATE(sum(Sales[Sales]),OrderTime[Order Year]= CONCATENATE( Year(NOW())-2,""))
In case of slicer use Min function put that in a variable.
 
Article
Anonymous
Not applicable

I tried putting in the min and max dates and still nothing on the py calculation. 

Can you please share the formula.

Anonymous
Not applicable

I found this to gives a result back have not confirmed if this is produces correct numbers

Cases PY = CALCULATE (
            [Cases PY],
            ALL ( Sale ),
            columnFilter1
        )

 

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.