Forum Discussion

kkandral's avatar
kkandral
Regular Visitor
6 years ago

SAMELASTPERIOD BUG Continues similarly

I have just two tables Sales and Calendar

Sales

Date_of_S     Amount

10/1/2019         100$

4/2/2019            60$

5/2/2019            50$

28/2/2019        200$

10/1/2020          75$

1/2/2020            30$

3/2/2020            10$

4/2/2020            45$

5/2/2020            85$

 

calendar has been genarated with dates between two vars 

minD =calculate (min(dates_of_S),all(sales)) -- 10/1/2019

MaxD =calculate (max(dates_of_S),all(sales)) --  5/2/2020 

TotSales= sum(sales.amount)

TotalSalesLY= calculate(TotSales,sameperiodlastyear(calendar.date))  -- calendar is connected many to one with sales and has been declared as a dateTable on the model

* When I see Jan20 compared to Jan19 everything's perfect 

*When I see the sales of the period Feb2020 I receive TotSales 170$ (30+10+45+85)and TotSalesLY 310$ which is incorrect (this is the sum of Feb19 includes the sales of 28/2/2019) 

* When I use slicer and I select dates up to 4/2/2020 I receive correctly  TotSales 85$ (30+10+45) and TotSalesLY correctly 60$

* When I use multiple selection only 1/2/2020 and 5/2/2020 excluded the 4/2/2020 I receive 115$(30+85) and correctly for LY just 50$ (sales on 5/2/2019) 

* Crazy!! when I use multiple dates and I choose e.g 1/2 2/2 ___ ___  5/2 the result is correct

BUT when I use 1/2 __ __ 4/2 & 5/2 the last two dates of February returns the Total of February2019 310$ again ... (I give up)... The symptom meets the situation when you choose the 2 latest days of your sales?!?!?    

----

I should use eomonth functions to avoid that or hasnofilter IFs. 

Another aspect is when I use the sales date TotSalesLY= calculate(TotSales,sameperiodlastyear(sales.date_of_S)) the measure returns blank... 

I suspect there is a problem with the connection of my Calendar or something DAX systemic or my ignorance 

Thank you in advance

 ----

P.S SALES table derives from two tables appended in PowerQuery e.g Sales2019 into --> Sales

4 Replies

  • I'd like to ask what the ultimate goal is here to best help.

     

    Try this first however - 

     

    TotSales = SUM (Sales.Amount)

     

    AND

     

    TotSales LY = CALCULATE ( [TotSales], DATEADD ( calendar.date , -1, YEAR )

    • kkandral's avatar
      kkandral
      Regular Visitor

      Has exactly the same reaction... Crazy? If I choose the first & last two dates of my date table returns 310$  

      • AlexAlberga727's avatar
        AlexAlberga727
        Icon for Resolver II rankResolver II

        Can you share the values for the days you're trying to calculate? I'd like to play around with it a bit and provide a solution

         

    • kkandral's avatar
      kkandral
      Regular Visitor

      The ultimate goal is to get the LastYear exactly of what I have in the CurrentYear