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])
)
)
)
Related
I have a table (we'll just call it MyTable) in PowerBI that includes a Date column. I have created a DateDimension table using CALENDARAUTO() with columns for the Date, Month#, MonthName, etc and created the relationship between that Date and the Date in MyTable.
I want to calculate the average year based on the records in MyTable. For example, if I have records with 1/1/2005, 1/1/2014, and 1/1/2015, the average year should be 2011.
How would I go about doing that? I've tried doing a measure of AVERAGE(DateDimension[Year]) and adding that to a Card visual, but it just shows 2.01K. If I do FORMAT(AVERAGE(DateDimension[Year]), "####"), the average is completely wrong.
Since you already have this DateDimension table, use
Average =
AVERAGEX(
MyTable,
RELATED(DateDimension[Year])
)
You can control the formatting by clicking on the measure (Average) and then using the Measure tools pane:
Set it to Whole number and no thousands operator.
Hi DAX Experts around the world,
I hope you can help me with below problem. In short:
there are two fact tables: Table1 and Table2 , not connected between each other and cannot be appended.
they have both relation to Calendar table
I need to create a measure which will return some part from Table1 and a part form Table2, as described on the picture.
When a Nov-21 is selected on the slicer, measure should return Actuals for first 10 months of the year with 100 each month (from Table1) and remaining 2 months with Forecast values from with 200 each month (from Table2).
Is it possible at all as I am out of ideas ?
Thank you in advance.
Max
You can create a copy of the calendar table(Calender (2)), which can be used to create a slicer.
With the help of this table, you can create a measure to calculate the value based on selected date like this:
Amount Measure =
VAR _selected_date = MAX('Calender (2)'[Date])
return SUMX(SUMMARIZE(Calender,Calender[Date]),IF('Calender'[Date]<_selected_date,SUMX(FILTER(Table1,Table1[Version]="Actual"),[Amount]),SUM(Table2[Amount])))
I'm learning DAX and I'm trying to make a measure for Sales Last year.
this formula works :
Sales LY = CALCULATE([Sales CY],SAMEPERIODLASTYEAR(Date[Date]))
But when I add FILTER to the measure, it gives me the values from the current year like "Sales CY"
Sales LY = `CALCULATE([Sales CY], Filter (dim_date, SAMEPERIODLASTYEAR (Date[Date]) ))`
I already have a date filter on the page relative date in this year
the invoices Table and Date table are joined on the date of the creation of the invoice (createdat)
Any ideas what's the meaning behind the things in blue circles?
The FILTER function expects a condition that can be checked for each row of the table instead of a column of dates returned by SAMEPERIODLASTYEAR, so I wouldn't expect the second version to work.
I think the bits circled in blue are emphasizing that you are connected an imported data table to a DirectQuery table (different storage modes).
I have a Power BI/DAX question. I'm looking to summarize my data by getting monthly transaction sums (including the year as well, i.e. MM/YY) and filtering them by individual account numbers. Here is an example:
I want to take that and make it into this:
I converted the dates to the format I want with this code:
Transaction Month = MONTH(Table[Date]) & "/" & YEAR(Table[Date])
Then got the total monthly sum:
Total Monthly Sum = CALCULATE(sum(Table[Transaction Amount]),ALLEXCEPT(Table, Table[Transaction Month]))
Now I'm trying to figure out how to filter the total monthly sum by individual account numbers. Just as a note - I need this to be a calculated column as well because I'll want to identify accounts that surpass individual account monthly spending limits. Can anyone help me with this?
Thanks so much!
When working with calendar dates, it pays to have a calendar table linked to the transaction table. In the calendar table you will have each date, from the start date of your relevant time period to the end of the time period relevant to your data. The columns of the calendar table can then contain calculations on that date like month number, month name, year, year-month key, transaction month (as the first day of the month for the date in that row), etc.
Next, connect the two tables in the data model by dragging the transaction date to the calendar date column.
Now you can build charts and report tables that group data by month without writing any complicated DAX. Just pull the field "transaction month" from the calendar table and the Total Sum measure from the transaction table into the field well of the visual.
That's what Power BI is all about.
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.