Dax TotalYTD and SamePeriodLastYear Not working - powerbi

Hi I am trying to get total YTD amount for last year.
When I select October 2020 my current YTD amount works here is what it looks like :
YTDAmount = TOTALYTD(sum(PCSReport[PD]),PCSReport[PCSMonth])
However, I want to show YTD October 2019 and for some reason it is showing blank. This is the DAX I made :
LYTDAmount = TOTALYTD(sum(PCSReport[PD]), SAMEPERIODLASTYEAR(PCSReport[PCSMonth]) )

Since your calculations are correct, here is what might be the problem.
To work with time intelligence functions (TOTALYTD,DATESYTD ... ) you must have at leat one date table with an active relationship to your fact table.
A date table is a table that meets the following requirements:
It must have a column of data type date (or date/time)—known as the date column.
The date column must contain unique values.
The date column must not contain BLANKs.
The date column must not have any missing dates.
The date column must span full years. A year isn't necessarily a calendar year (January-December).
The date table must be marked as a date table.

Related

PowerBI next month function is not rolling over a year, any advice?

I have a column called Snapshot Effective Period (next month) which is the Nextmonth([Snapshot Period]). This function stops when the snapshot period is 12/1/2021, what I expect to see is 1/1/2022 when the snapshot period is 12/1/2021. The value is not rolling over a year. Any advice?
Snapshot effective period next month c1 is a calculated column in date format.
Snapshot Effective Period (Next Month) c1 = NEXTMONTH('Forecast Detail'[Snapshot Period])
NEXTMONTH function should be used on Calendar
Notes In order to use any time intelligence calculation, you need a
well-formed date table. The Date table must satisfy the following
requirements:
All dates need to be present for the years required. The Date table
must always start on January 1 and end on December 31, including all
the days in this range. If the report only references fiscal years,
then the date table must include all the dates from the first to the
last day of a fiscal year. For example, if the fiscal year 2008 starts
on July 1, 2007, then the Date table must include all the days from
July 1, 2007 to June 30, 2008. There needs to be a column with a
DateTime or Date data type containing unique values. This column is
usually called Date. Even though the Date column is often used to
define relationships with other tables, this is not required. Still,
the Date column must contain unique values and should be referenced by
the Mark as Date Table feature. In case the column also contains a
time part, no time should be used – for example, the time should
always be 12:00 am. The Date table must be marked as a date table in
the model, in case the relationship between the Date table and any
other table is not based on the Date.
https://dax.guide/nextmonth/
Instead of NEXTMONTH use DATE
Snapshot Effective Period (Next Month) c1 = DATE( YEAR('Forecast Detail'[Snapshot Period]), MONTH('Forecast Detail'[Snapshot Period]) +1, DAY('Forecast Detail'[Snapshot Period]))

Finding Previous year Sales in Power BI with week number

I am trying to find the Previous year sales for the same week in Power BI.I dont have any date column.
I have two table one is FACT Indicators table as shown below:
and one sales table( Fact Sales table):
I want to create one calculated field namely(Sales Previous Year) to show the previous year sales for the same week .
In 'Fact Indicators' table 'PY 52 week flag' filed shows if this week id is Previous year or not.
Week column shows the week number from 1 to 52 weeks .
Week Id shows the unique number per Market key.
'Market_Week Id Key' is the common joining key between FACT Indicators table and Fact Sales table
Please help me to find the formula for calculated field.I dont have the date field in my raw data
Every time you deal with anything related to dates, you will need to add what we call a date dimension. It will save you tons of headaches. Once you have it in you will be able to hook it into the creation of the calculated filed.
you can google power bi or ssas date dimension and find tons of information on it.
Yeah! I guess SQL Technical team can be a tough crowd.... Well! In this case, I would recommend bringing the Year into FactSales Table from Fact Indicator . You have two options here with physical relationship set up between Market Week Id Key in both tables you can build a calc column with
Year = CALCULATE(VALUES(FactIndicators[Year]))
or without relationship use LOOKUPVALUE on WeekId
Year = LOOKUPVALUE(FactIndicators[Year], FactIndicators[WeekId], FactSales[WeekId])
Sales Last Year calc colum :
SalesLastYear =
CALCULATE (
SUM(FactSales[SalesThisYear] ),
TOPN(1,
FILTER(
FactSales,
FactSales[Year] < EARLIER(FactSales[Year])
&& FactSales[Key] < EARLIER(FactSales[Key])
)
)
)

In Power bi Date slicer can we only show the end of month dates instead of showing all the dates?

I have a report where I have sales data for end of every month. When I see the data in drop down ,I can see the end of month date , but when I have used slicer it shows the entire date range and not only the last day of the month. Is there any way in slicer through which I can just limit the date, so that only last day of month will be shown in slicer ?
If you have a dates table with a date field (named Date, in this case), you could add a column with this code: Table.AddColumn(PreviousStep, "EndOfMonth", each Date.EndOfMonth([Date]), type date)

Power BI growth rate calculation YoY

I'm having some difficulty getting a YoY change % for values in Power BI. The averages don't come out proper. I've come to understand this is an AVERAGE vs AVERAGEX issue in Power BI.
I need to create charts of year on year growth monthly. So Jan20 % change from Jan 19. I thought what was below was correct, but it is always throwing an issue for the month of February and a few other months. But some of the months are correct. My Measure is below.
Growth =
IF(
ISFILTERED('Oct5_5'[TRAFFIC_DTE]),
ERROR("Check Time Filter."),
VAR PrevMonth =
CALCULATE(
AVERAGE('Oct5_5'[VISITS_AMT]),
DATEADD('Oct5_5'[TRAFFIC_DTE].[Date], -12, MONTH)
)
RETURN
DIVIDE(
AVERAGE('Oct5_5'[VISITS_AMT]) - PrevMonth,
PrevMonth
)
)
Snippet
Can someone please show me how to use the right Average? Thank you so much!
Do You have all calendar days in your traffice_dte?
Probably not. This causes you to go back to a date that does not exist, which causes an error.
DATEADD function work ok if you use it on "calendar" tabel.
Requirement below:
https://dax.guide/dateadd/
The Date table must always start on January 1 and end on December 31, including all the days in this range. If the report only references fiscal years, then the date table must include all the dates from the first to the last day of a fiscal year. For example, if the fiscal year 2008 starts on July 1, 2007, then the Date table must include all the days from July 1, 2007 to June 30, 2008.
There needs to be a column with a DateTime or Date data type containing unique values. This column is usually called Date. Even though the Date column is often used to define relationships with other tables, this is not required. Still, the Date column must contain unique values and should be referenced by the Mark as Date Table feature. In case the column also contains a time part, no time should be used – for example, the time should always be 12:00 am.
The Date table must be marked as a date table in the model, in case the relationship between the Date table and any other table is not based on the Date.

Power Query PREVIOUSDAY over weekends, holidays

I have a table with columns date, warehouse, stock code, units. The date is linked to a calendar table, which has a true/false column which days are 'valuation days', meaning weekdays and non holiday days.
I've created a column with
previous day units =calculate(sum('Table'[Units]),
PREVIOUSDAY('Calendar'[Date]),
ALLEXCEPT('Table','Table'[Product],'Table'[Warehouse]))
That column succesfully shows the previous day's stock for each warehouse / product combination, but on Mondays it compares stock levels to Sunday, which doesn't have an entry in Table, and so is zero. I need to compare Monday to Friday.
There's lots of similar queries, but I can't for the life of me find a solution that works when I have this warehouse / product combination in my table.
Table
Pretty sure i found myself the solution. I created another custom column which used LOOKUPVALUE to bring the a field 'PrevValuation Day' into 'Table' and then used
=calculate(sum('Table'[Units]),
filter(ALLEXCEPT('Table','Table'[Product],'Table'[Warehouse]),'Table'[Date]=EARLIER('Table'[PrevValuationDay])
))
and that seems to work.