How can I pass user input from a what-if parameter to be used in a calculation in a measure? - powerbi

I'm new to Power BI so please bear with me, I've searched extensively for a solution but haven't been able to find quite the right thing.
I have a data set that contains (among other things) transactions with amounts and financial periods stored as whole numbers, and what I need to do is use those to arrive at YTD totals. So the user would select a period from 1-12 and then the YTD measure should calculate the totals for the selected period PLUS the previous periods (said another way, it should filter OUT the periods greater than the selected period).
I've tried to filter the totals for the appropriate periods by referencing the selected value of the parameter using "<=" but haven't been able to make that work:
ytd = CALCULATE(SUM(data_tbl[Calculated USD]),data_tbl[PERIOD NUMBER]<=current_period[current_period Value])
I'm probably approaching this the wrong way, but somehow I need to calculate YTD based on the user selecting the desired period. Thanks for any advice.

Related

Dax measure to avoid all slicers except one in Power BI

Here, I have a dataset in which there is an eventid (ID) captured for each event generating in each department(DEPT), with its timestamp(event-time).
Each event captured is categorized as OPEN/ CLOSE(event status).
I want to show the efficiency of each department, which is defined as-
Total cases closed Divided by Total no. of cases registered in that Department.
I tried using 100% stacked bar chart, but the result in it changes every time a different slicer is selected.
Please Help.
You'll need to use a combination of CALCULATE and ALLEXCEPT. THe resulting measure will look something like this:
NewMeasure := CALCULATE([OriginalMeasure], ALLEXCEPT('MyTable'[Field To Keep Filters ON]))

Can a measure be created in Power BI that references two tables that share no relationship?

I'm trying to create a matrix table in Power BI to display the monthly rent projections for a number of properties. I thought I could simply create a measure that summed the rent from one table and then displayed it by month based on start and end date conditions, but it's been a while since I created any measures and I had forgotten that there needs to be a relationship between columns, among other things.
Data Model
A site can have more than one lease associated with it and a lease can have both car-parks and floors associated with it, of which there can be multiple.
In addition to the tables in the linked image, once I had sorted out what I thought would be the easy step I was going to add another table which includes the estimated percentage rent increase and the period in which the increase will occur.
I started out by trying to create a measure along the lines of the following:
Matrix Test =
IF (
HASONEVALUE ( Period[Month] ),
IF (
Period[Month] >= Leases[Custom Start Date],
SUM ( Floor_Rent[Annual Rent] ) / 12,
0
),
0
)
This would need to be expanded upon because the end date of a lease would also need to be taken into consideration.
As well as forgetting about the relationship requirements, I've forgotten how to deal with the issue of narrowing down to a single value within a column.
The result is supposed to be something that looks like this:
The blanks indicate a lease that starts in the future or ends within the time-frame displayed.
When I try linking the Leases table and the Period table on Leases[Start month for current term] and Period[Month] all I can get to is a table that shows the rent amount in the month the lease starts.
Is what I'm trying to achieve possible? If so, how do I accomplish the desired result?
Link to .pbix file
Solution
The direct answer to the title question is probably 'no', but while trying to figure out how I could use Pratik Bhavsar's LOOKUPVALUE suggestion I had a thought and performed a clumsy google search - power bi create table for each value in column - and found this post. By meddling with some of the DAX in said post I was able to come up with the following:
Test Table =
GENERATE(
SELECTCOLUMNS(
VALUES(Leases[Lease ID]),"Lease ID",[Lease ID]
),
SELECTCOLUMNS(
VALUES(Period[Month]),"Month",[Month]
)
)
The result is a table with each Lease ID mapped against each Month. I can't claim to understand exactly how the functions work, and it's not the outcome I thought I needed, but it allows me to achieve exactly what I set out to do.
I've accepted Pratik Bhavsar's answer because it effectively accomplishes the same thing as the work around I implemented. Pratik's solution might be better than what I eventually landed on, but I need to have a closer look at how the two compare.
The following DAX will give you a table with all buildings mapped against all rows in the period table, eliminating the requirement of a relationship.
SiteToPeriod =
CROSSJOIN(
SELECTCOLUMNS(Sites1, "Building name/label", Sites1[Building name/label]),
Period
)

Power BI YTD Calculations

I am trying to do some time based calculations on my budgeting data but struggling to understand where I'm going wrong or if my data structure would even support what I'm trying to do.
As per the image above, this is my raw data. ie. A monthly budgeted and actual total for each cost centre that is being imported from an excel spreadsheet.
I am trying to calculate a YTD budget and YTD Actual figure per cost centre based on the monthly totals. Ideally I would like all of this data displayed in a table that I can then use slicers to segment/pivot.
When using the CALCULATE() function in a measure, I am unable to select my cell value for each date and cost centre.
eg.
YTD Actual = CALCULATE( [Actual MTH] , DATESYTD('Dates'[Date], "30/6"))
returns the error
The value for 'Actual MTH' cannot be determined. Either 'Actual MTH'
doesn't exist, or there is no current row for a column named 'Actual
MTH'.
Any assistance with getting a greater understanding of the issue here would be appreciated.
Thanks
Try something like this for your measures:
YTD Actual = TOTALYTD(sum([Actual MTH]),'Dates'[date],ALL('Dates'[date]),"30/6")

Annual Percentage Change in Power BI

I am looking to calculate an annual percentage change, from today of a number of stock market indices. The data is a flat structure un-pivoted about the date column.
I am using a calendar with daily values extending to the end of the current year. My current code:
Ann pch =
VAR
__EarliestValue = CALCULATE(SUM('Equity Markets (2)'[Value]),
SAMEPERIODLASTYEAR( 'Calendar'[Date]))
VAR __LastDateValue = SUM('Equity Markets (2)'[Value])
RETURN
CALCULATE(
DIVIDE(__LastDateValue,__EarliestValue)-1)
returns answers which are clearly incorrect.
I am very much a DAX/PBI novice.
DATA:
I also have a Calendar table:
I think that the metric is actually correct, what makes you believe it is not? Can you share your output?
What you need to do now is to put it into a context, ie put 'Calendar[Date]' into the desired visual (table for instance). If you don't do so, you'll calculate the total amount of value divided by the total amount of value for dates prior to one year, which might return quite a weird number. If you do so, on the other hand, you should get your YoY comparison.
Something to note - there are also quick measures:
Check them out, as one of them is actually YoY total, which you might want to try.

Calculate rates from previous month based on current month in order to make then visually comparable

Maybe this is an easy one but since I’m very new in DAX and PowerBI I can’t figure it out. My database has daily data ranging from MAY/17 to JUN/17 (and it’ll still going in the future). It has information of DATE, DAY, YRMTH (year-month), QT_APRV (approved customers) and QT_TOTAL (total consumers). Sample below (using Excel just to be quicker):
I wanted to create in PowerBI a bar chart with QT_TOTAL per day and a line chart with approved rate of consumer. For the rate, I used:
APPRV_RT = SUM(database[QT_APRV]/SUM(database[QT_TOTAL])
And then, selecting only a month by time in the chart (just like I want), I have:
Perfect, but now I want to create a new line chart, showing the approved rate in each respective day of the last month. Using my example, when june data are select, the first line chart has to show the daily approved rate of june AND the other the approved rate of may, in order to make it comparable (june1 -> may1; june12 -> may12 and so on). Here’s what I want:
How to make this automatically, in order to make each month comparable with the previous? I thought about some DAX formula involving a sum with filtering current month minus 1, I don’t know how to do it.
Any ideas?
UPDATE (07/08/2017)
I tried what Rasmus Dybkjær suggested me, and I thing I'm in the right path.
APPROVED_RATE_PREVIOUS_MONTH = CALCULATE([APPROVED_RATE_CURRENT_MONTH];PARALLELPERIOD(dCalendario[DataBase];-1;MONTH))
However, it returned the approved rate from the previous month as a whole (67,0% in May), not each day as I wanted:
Any suggestions?
You should be able to use the DAX function called PARALLELPERIOD() for this purpose. The PARALLELPERIOD() function takes a date column and shifts it a number of periods back or forward.
For example, you could use it like this to calculate your approved rate shifted one month back:
ApprovedRateLM =
CALCULATE(
DIVIDE(
SUM(database[QT_APRV]),
SUM(database[QT_TOTAL])
),
PARALLELPERIOD(database[Date],-1,month)
)
Note that it is important that your [Date] column contains a date type. Otherwise the PARALLELPERIOD function will not work.