In power BI, I am computing the percentage difference between Stock price index levels over the last year.
Ann pch =
VAR __EarliestValue = CALCULATE(SUM('Equity Markets (2)'[Value]),
DATEADD(LASTDATE('Calendar'[Date]),-1,YEAR))
VAR __LastDateValue = CALCULATE(SUM('Equity Markets (2)'[Value]),
LASTDATE('Calendar'[Date]))
RETURN
CALCULATE(
DIVIDE(__LastDateValue,__EarliestValue) -1)
The above is correct but there is a bug: some dates fall on the weekend, or other non-trading days, in which case I want to select the next nonblank value for __EarliestValue and the previous nonblank value in the case of __LastDateValue.
Could anyone suggest the code to implement this.
I am very much a DAX/Power BI novice. Thank you very much.
Data Sample:
I created a slicer based on the column 'Equity Markets(2)'[Date].
note: Do not make the slicer on your calendar date, then you get your "holes"
Then I created a measure with following formula:
Measure = LOOKUPVALUE(EquityMarkets[Value];EquityMarkets[Date]; MAX(EquityMarkets[Date]))/ LOOKUPVALUE(EquityMarkets[Value];EquityMarkets[Date]; MIN(EquityMarkets[Date]))
This measure I show in the card visual. The result is when using the slicer, the calculation is made.
Related
I am new in Power BI, and I am struggling with how to resolve an issue.
I made measures to calculate my total feedback. The feedback column can be POS, NEG, and Neutral. The overall sentiment I calculated by taking pos feedback and dividing by all feedback.
totalFeedback = CALCULATE(COUNTROWS('feeback'),'feedback'[sentiment] = "POS")/ COUNTA('feedback'[sentiment])
Now when I want to calculate the difference between two months. Example today's, and last month I get an error saying duplicates dates.
difference = CALCULATE([totalFeedback], DATEADD(FILTER('comment'[created_at], 'comment'[created_at] < TODAY()),-1,MONTH)
I get an error saying: A date column containing duplicate dates was specified in the call to function 'DATEADD'. This is not supported
What I did was I created a DATE TABLE and made a relationship with the comment[created_at].
DimDate= CALENDARAUTO(12).
Now, I don't get the error anymore, but non of the data is shown when adding the measure in the table.
I need advice, thanks
I am trying to use a row level formula to filter down a series of opportunities to ones which occur at the end of the month, or within 2/3 days of the end of the month.
I have the following columns: "Opp name", offer submission date, "closed date"
Purpose of the exercise: I would like to identify opportunities which have an offer submission date at the end of the month. Currently, I have filtered the report to last month.
What I would like to do: I would like to filter the data down using a row level formula, so that I have all the opportunities which have an offer submission date around the end of the last month NOT just in the last month.
Please could someone advise me as to the syntax for such a row level formula. Huge thanks in advance!
**** Edit****
This is now what my formula looks like.
And the results are:
As you can see, the records which should be highlighted as 1 (and therefore 'True') aren't. Any help would be hugely appreciated.
My formula runs on Case Last Modified Date, you'll have to change field name. And mine's "DateTime" really, if your custom field is Date only - you don't need DATEVALUE().
For illustration let's say anything after 20th is month's end
IF(DAY(DATEVALUE(LAST_UPDATE)) > 20, 1, 0)
Looks promising:
You can decide to make it a Text formula or maybe really just display the day of the month and filter / sort by it... Doesn't matter much, all yours?
I need to create a Measure that would display the number of tasks that are over due, based on today's date.
So basically I need to translate this into DAX in power BI?
SUM(If DueDate is greater then today then count it as OverDueTask)
I tried to do something like that but when trying to display it it says:
Cant display the visual
OverDueTasks = CALCULATE(SUM(TotalCounts[DueDate]), FILTER(TotalCounts,[DueDate]>TODAY()))
I tried your formula and the issue appears to be the SUM. You are summing dates so Power BI is going to treat them like dates, but the formula goes past the threshold for dates. Change the SUM to a COUNT and it should work.
OverDueTasks = CALCULATE(
COUNT(TotalCounts[DueDate]),
FILTER(
TotalCounts,
[DueDate] > TODAY() &&
[CompletedDate] = ""
)
)
you should first create a calculated column with formula
=IF(Table1[DueDate]>TODAY()|1|0)
Then a measure to sum this up
Overdue:=SUM(Table1[Calculated Column 1])
I am pulling Facebook Fan data daily via Supermetrics into Data Studio and I was hoping someone could share a formula that I could use to calculate New Fans, as a calculated field, from Total Fans.
The formula would need Identify the last day of the month and the subtract followers from the first day of the month.
For example: If there 100 Fans at the end of September and 60 Fans at the beginning September, the formula would show 40 New Fans.
Formula Example
Assuming the net fan numbers is always increasing, first set the aggregation method for Total Fans to None in Fields screen by editing the data source. Then you can create a new calculated metric with the formula max(Total Fans)-min(Total Fans). This will work only at aggregate level (using scorecard or table total) and not at row level in tables.
When choose a single Year on slicer I want area chart display all data from that chosen year and till the end (all years I have in my datasource).
But instead it just displays me the data for single year choosing on a slicer.
So I have this:
But I want it look like this: whatever Year I choose in slicer - chart will show all data starting from 2014 and goes till 2017.
I am simply following a PowerBI template example and it seems like it's possible to do that:
https://app.powerbi.com/view?r=eyJrIjoiMjc2NzExODItMjNhYy00ZWMxLWI2NGItYjFiNWMzYzUzMzhlIiwidCI6IjU3NGMzZTU2LTQ5MjQtNDAwNC1hZDFhLWQ4NDI3ZTdkYjI0MSIsImMiOjZ9
This is doable but it requires some tricks and extra measures.
TL;DR: The slicer you see is actually served as a value picker, not as a filter. An extra measure based on the value is created and used as visual level filter for the visual to do the trick.
If you want to follow along, you can download the .pbix file from this Microsoft edX course about Power BI.
First, create a new table based on the existing Date table, with only distinct years:
Year = DISTINCT('Date'[Year])
Then, create a slicer with the Year column from the newly created Year table (NOT the Date table).
A measure (used as flag) is created as follows:
Flag =
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) >= YearSelected, 1, 0)
So basically it gets the year selected from the year slicer and compare it with the year value in the date table to see if it's greater than or equal to it.
The chart is created with Year column from the Date table (NOT the Year table), and other needed measures. Flag is added to the Visual level filters and set to 1.
So the Flag value will change according to the value picked in the Year slicer, and served as the actual filter to the chart displayed.
Results:
EDIT: on more use cases
#Oleg Try to think of how you can apply the Flag concept further. For example, if you want another chart displaying data of the same year as the slicer, you can set up another flag called SameYearFlag and only change the part of value comparison to =. Add it to the chart Visual level filter and it'll show only data in the same year. Yes, by extension, that means you can have another flags like LastYearFlag, NextYearFlag, etc, as long as it makes sense to you. The use case is up to you.
LastYearFlag =
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(YearSelected - VALUES('Date'[Year]) = 1, 1, 0)
NextYearFlag =
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) - YearSelected = 1, 1, 0)
SameYearFlag =
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) = YearSelected, 1, 0)
Examples:
By having only one year slicer, I can have charts with data in the same year, last year, next year and all years following, by applying different flags to them.
As said, it's up to you to come up with more interesting use cases!
I would propose to consider the new numeric range slicer.
You can just set it as "Greater than or equal to". Users can select then the initial year in the range by entering the number or dragging the slicer.
You would need to enable this feature in Power Bi Desktop, Options under "Preview features".
Is well presented in the documentation https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-slicer-numeric-range/
This is how it could look like: