power bi dax last value over a period - powerbi

I have this table below. How to get Revenue_MTD in DAX? Revenue_MTD equals to the revenue of the last month of each year. The tables are from Tableau and I am converting these to power bi.
with only years:

If you want to get the revenue of the same month previous year you can add a calculated column with this type of dax expression :
Revenue_MTD = SUM(Revenue),
PARALLELPERIOD(
[Date],
-12,
MONTH)
)
you can have more detail on this link :
https://radacad.com/dateadd-vs-parallelperiod-vs-sameperiodlastyear-dax-time-intelligence-question

This is a standard powerbi measure, it should be fairly easy for you to implement this.
MEASURE = CLOSINGBALANCEYEAR(,[,][,])
.
.
.
MEASURE = CLOSINGBALANCEYEAR(SUM(Revenue), DATE )
As long as you have a Date column with appropriate Date Column it should work.
then create another measure with only SUM(revenue)

What expression are you using for your [Revenue_MTD]? Are you using the built-in DAX function TOTALMTD?

Related

Date differences in Power BI- Power Query

Hello Everyone i am trying to get a Days Interval column through getting the differnce between Todays Date and a column Refresh date in Power Query, How do i go about it.
I want to do this in Power Query
= DateTime.Date(DateTime.LocalNow())-[Refresh Date]

Sum over partition by- Power bi

I am trying to achieve this using dax.
I have a table with date, month, year and amount.
I want to create a measure which gives me the desired output in power bi.
This desired output only changes every time there is a change in the date, month and year.
Try the following measure :
DesiredOutput = CALCULATE(
SUM('yourTable'[Amount]),
FILTER(ALL('yourTable'),
'yourTable'[Month]=MAX('yourTable'[Month])))

seeing sales data by "WEEK' in power bi

Can you help me figure out how to display sales data by "WEEKS" in power BI visuals ? I have a calendar table and the date hierarchy is listed by Year, Quarter, Month and Day with no week option.the visual I'd like to create is the chart at the bottom of the image I have attached Thanks
You need to add in the Week to your calendar.
If your are using DAX there are a number of ways
To show the week number of the year use WEEKNUM
Week No = WEEKNUM(Table1[Date], 2)
For the start of the week in a date format use
Start of Week = 'Calendar'[Date] - WEEKDAY('Calendar'[Date],2) +1
The equivalent functions in Power Query are Date.WeekOfYear and Date.StartOfWeek

power bi date measure card

I have a dashboard that needs to display the beginning of the week, on Monday, of the week that I'm in. So for example, if its 1/7/2020, this card would show 1/6/2020. Here is the code I was trying:
Report Date = CALCULATE(TODAY(), FILTER('Calendar', 'Calendar'[WeekStartDate]))
The column in the Calendar table is Weekstartdate, which is accurate and does show the week of 1/6/2020 with the corresponding dates to it; however, it looks like it won't filter it from today's date.
Any ideas? or advice on what I'm doing wrong?
If what you are looking for is a single date, which gives the week start date based on Today's date, you should create a measure:
WeekStartMeasure = TODAY()-WEEKDAY(Today(),2)+1
If you are creating week start date based on a column, then you should create a column with the following calculation:
WeekStartDate = Table[Date]- WEEKDAY(Table[Date],2)+1
Once you create the measure/column, you can use it in the visualization to get the desired result.
We can calculate this way also
if (
WEEKDAY(TODAY(),1) == 1,
TODAY(),
TODAY() - (WEEKDAY(TODAY(),1) - 1)
)

Power BI: Percent Change Formula

I want to create a simple percent change formula in power BI. Specifically, I want to evaluate month over month %change in cost. I know that percent change can be defined in different ways, so to be clear this is the formula that I am referring to:
%change = ([current value] - [previous value])/[previous value].
Here is an example in Excel of what I want to achieve:
I cannot find a way to target a specific row in a DAX formula. It seems that power BI only wants to include aggregate values such as sum, max, etc.
As a final note, I know that PowerBI includes a percent change "quick measure". However, the 'Base Value' always requires you to select aggregate measure instead of a single row value.
As Alexis mentioned, there is no concept of referring to a specific row in DAX. It can be a hard notion for people who are used to Excel, but if you want to take advantage of PowerBi, you will have to "unlearn" Excel way of thinking.
To accomplish your goal, you need to do some data modeling first. As a common practice, replace your "Date" column with a proper Calendar table:
Calendar table explained
As a result, you will have a data model in PowerBi that looks something like this:
Once you have such structure in place, DAX is simple:
Current Month Cost = SUM(Expenses[Cost])
Previous Month Cost = CALCULATE( [Current Month Cost], PREVIOUSMONTH(Calendar[Date]))
% Change = DIVIDE( [Current Month Cost] - [Previous Month Cost], [Previous Month Cost])
I used Earlier to get the previous date value for Open
Accum = var previousOpen=CALCULATE(MAX(EOG[Open]),FILTER(EOG,EOG[Date]<EARLIER('EOG'[Date],1))) return Divide(EOG[Open]-previousOpen,previousOpen)+1