MDX counting profit diff between years in % - visual-studio-2017

I have data about profits etc. and I want to count % increase/decrease from previous years (if there is one) for each year. Is there a better way to do that, than just do a specific calculated member for each year? My time dimension is server generated.

You could write a more generic calculated member that could work for Year and other levels on the time dimension.
You could use the Parallel Period mdx function to obtain the information for the previous sales. Then you can compare that to the current to get the percentage change.

Related

Measure to calculate Average Unit Cost providing unexpected values

I'd like to show the average unit cost in each year for a series of items I'm purchasing. I'll be purchasing 13 items over 10 years. In some years, I purchase multiple items, in others, I purchase only one.
My Measure is Sum(Cost)/DistinctCount(Items). In all cases, this results in a count of 13 items, rather than the number of items in a given year. For reference, I'm using this in a line chart, where years are along the x-axis, so I (wrongly) assumed that the Year context would apply. Any suggestions?
For example, in one year, I'm purchasing 5 items for $350 dollars, which should result in an average unit cost of $70, but is instead returning $26.92, which is 350/13.
If the year context doesn't apply, then it sounds like an issue with your data model. Have a look at whether there's a relationship from your Date table to your Fact table (the one with the item counts).

DAX Function to Return the Month Number of the Previous Month

I have a calculation where I need to divide the budget by 12 and then multiply by the number of months passed not including this month.
So for this month, I have DIVIDE([GP Budget $],12)*4. But I obviously don't want to have to change the calculation every month. My calendar table has a month number so I was hoping to return that value depending on what the previous month is. I'm sure there are about a thousand ways to do this but I'm still new to BI and my Bing searches are failing me.

Find MAX 7 day average with DAX

I am stuck trying to build a measure to determine the best or max 7 day average over a period longer than 7 days.
I have multiple values for each day, the measure needs to sum the values by day then calculate a rolling 7 day average then determine which of those results is the MAX value.
Could you help point me in the right direction please?
You need to use define a column in your measure and run an iterator (MAXX) over it in order to find the maximum value. Without additional details about fields and data model it is hard to be more specific.
However, see below an example:
VAR _tbl = CALCULATETABLE(ADDCOLUMNS(
SUMMARIZE('Fact', 'Dimension 1'[Attribute 1], 'Dimension 2'[Attribute2]),
"#average", AVERAGE('Fact'[Attribute 2])
), ALLSELECTED('Dimension 1'), ALLSELECTED('Dimension 2))
RETURN
MAXX(_tbl, [#rolling_average])
In practice, first we define a table with the measures pre-calculated,
then, we run an iterator on that table in order to retrieve the maximum value.

Power Bi Calculating number of days dynamically

I am using a slicer to determine a certain periode of time (e.g. 01.10.19 - 31.10.19) and now I want Power Bi to calculate how many days are included (in this case it would be: 31). Of course the calculation needs to be updated every time I use the slicer. Is there any possibility to do so? I have literally no idea...
Create a measure to calculate the difference between the max and min dates in your date table, which is filtered by this slicer. You can use DATEDIFF function for that. In this case the number of days will be calculated as:
Number of days = DATEDIFF(MIN('Calendar'[Date]); MAX('Calendar'[Date]); DAY) + 1

Power BI Percentage of Month passed

I would like to create a calculated column or measure that shows the time elapsed in any given month. Preferably as a percentage.
I need to be able to compare productivity (rolling total) over a month's period between different months.So creating a percentage of time passed in a month would put every month on a level playing field.
Is there a way to do this?
Or is there a better way to compare productivity between 2 months on a rolling basis?
EDIT
I am graphing sales on a cumulative basis. Here is a picture of my graph to demonstrate.[][
Ideally I would like to be able to graph another person's sales on the same graph for a different month to compare.
The problem is each month is different and I don't think power bi allows much customization of the axes.
So I figured a potential solution would be to convert months to percentages of time passed, create two separate graphs and place them on top of each other to show the comparison of sales.
Using percentages doesn't sound right here: one person's "productivity" in February will appear lower than another person's productivity in March just because February has 3 less days.
Just use [Date].[Day].
To answer the original question (even though it shouldn't be used for this), month progress percentage calculated column:
MonthProgress% =
var DaysinMonth = DAY(
IF(
MONTH(MyTable[date]) = 12,
DATE(YEAR(MyTable[date]) + 1,1,1),
DATE(YEAR(MyTable[date]), MONTH(MyTable[date]) + 1, 1)
) - 1
)
return MyTable[date].[Day]/DaysinMonth*100
Also check DAX functions PARALLELPERIOD and DATEADD.
This is the solution I settled on.
I customized the ranges for the x and y axes so they match.
For the y-axis, I simply put the range from 0 to 50+ our highest month.
For the x-axis, I created a column with the DAY function so I got a number assigned to each day of the month which allowed me to manually set the chart range from 0 to 31. I have asked another question on how to only get workdays.