Why do i get the avrage of the subcategory and not the avrage of category per year? - powerbi

When i drag in a tabel
and just have
-YEAR
-Kategory
-Summa
I will get the medium value of 895,50 (815 + 976 / 2) for february
I don't want it to separeate the Subcategory
I want it to show
1791
when i just mark february
and if i use February and March
It sould say
2022 Inköp 2435,5
Becouse that the Medium of February and Marsh on the category

It's difficult to understand what you are asking (likely the reason for your downvotes). I think you are after a monthly average measure. Since your sample data is extremely limited I assume that each month will have exactly one date. Ideally this type of calculation should be handled by using a calendar table as a basis for month values, but for your sample data, try this:
Monthly average =
AVERAGEX (
VALUES ( 'Table'[Datum] ) ,
CALCULATE ( SUM ( 'Table'[Summa] ) )
)

Related

Compare Month to last years Month total

In power Bi, I am creating a report that compares this years data to last years. For example, I have January data for 2022 but I need to calculate all of the data for January in 2021. In the pic, I have CY (current year) data for January. The second matrix would display the Previous year data. the data in the PY pic is not correct. Can someone help me figure out a dax formula for it?
So the answer is going to depend on whether you have a date table in your model or not. But essentially, you need to change the filter context for the previous/last year measure using the CALCULATE function.
As an aside, I noticed your column names between the pictures were not really similar, i.e. Sales Order seems different than Actual Shipping. But in any case...
With a date table
PY Calculation = CALCULATE(
SUM( YourTable[YourColumn] ), // or some other calculation...
SAMEPERIODLASTYEAR( DateTable[Date] )
)
Without a date table
PY Calculation = CALCULATE(
SUM( YourTable[YourColumn] ), // or some other calculation...
SAMEPERIODLASTYEAR( YourTable[SomeDateColumn].[Date] )
)
Let me know if that worked for you. (And yes, there are other ways to accomplish the same thing.)

To add Life to date measures with a date slicer on the report

I am facing this issue in understanding how to add a measure Amount LTD which looks back to all the data for projects since its start.
I am able to give total amounts per project between the dates on the data slicer but unable to get Amount which looks back beyond the data filters applied and get the LTD sum value till the to date selected on the date slicer.
Can someone please help.
TIA.
See this Cumulative Total pattern.
Cumulative Quantity :=
CALCULATE (
    SUM ( Transactions[Quantity] ),
    FILTER (
        ALL ( 'Date'[Date] ),
        'Date'[Date] <= MAX ( 'Date'[Date] )
    )
)

Show balance by month - Power BI

I have data about bank transactions. For example, I have two attributes "Posting date" and "Value". I want to see bank balance by each month. Problem is, that if I create measure and then add to graph (by months) I get SUM by each month in graph, but this is not balance.
For example, if data:
01.01.2019 (500€)
02.01.2019 (100€)
24.01.2019 (-50€)
25.01.2019 (-200€)
04.02.2019 (100€)
15.02.2019 (-50€)
03.03.2019 (200€)
I need that kind of result:
January (350€)
February (400€)
March (600€)
But I get:
January (350€)
February (50€)
March (200€)
I found solution:
Balance =
CALCULATE (
SUM ( Dataset[Value] );
FILTER (
ALL ( Dataset);
Dataset[Posting Date] <= MAX (Dataset[Posting Date] )
)
)

Working with Duration (Availability) in PowerBi

I'm trying to create a line graph in PowerBI. What I am trying to plot is somewhat complex.
I have the following tables:
Staffing - this table describes staffing for every employee in the company. By "staffing" I'm referring to how their time is allocated. For example, Employee #7 is staffed in "Chicken Manufacturing" with a StartDate of 1/1/2016 and an EndDate of 1/10/2016
EmployeeID Project StartDate EndDate
5 Cutting Lemons 12/1/2015 12/31/2015
5 Chicken Manufacturing 1/1/2016 1/10/2016
6 Fishing Lobsters 1/2/2016 1/5/2016
7 Chicken Manufacturing 1/5/2016 2/1/2016
8 Drinking 2/1/2016 null
I also have a standard Date dimension as well as an Employees table and a Project table. The Employees table has a row for every employee and the Project has a row for each activity.
I am trying to create a line graph that has dates on the x-axis and the line will show me how many employees are active at the given date. So for dates 12/1/2015 - 1/10/2016 Employee 5 should be counted as "Staffed" but on 1/11/2016, he should not be included in the total.
What I'm actually trying to do is calculate Availability and by that I mean, how many Employee hours are available on each day (I have a project called Available) so ultimately I will want to count the number of Hours rather than employees, but I think if I can get to work with counting employees, I shouldn't have too much trouble multiplying number of employees by 8 hours per day.
Try something like this:
Count of Emp =
CALCULATE (
DISTINCTCOUNT ( Employee[EmployeeID] ),
FILTER (
Staffing,
[StartDate] <= MAX ( 'Date'[Date] )
&& (
[EndDate] >= MAX ( 'Date'[Date] )
|| ISBLANK ( [EndDate] )
)
)
)
It is not tested but should work as long as you have relatinship between Employee - Staffing. Also be sure to use your date column in the Axis setting.
Let me know if this helps.

DAX Previous Month to date total is giving entire previous month's entire total

I am using DAX in Power BI to calculate Previous Month sales total to date to create a KPI visual. i.e. if today is 7th Dec then I want to get sales total from 1st Nov to 7th Nov and compare with current month to date.
CurrentMTD = TOTALMTD(SUM(SALES_VOUCHERS[SaleValue]),DatesTable[Date])
This works fine.
However Previous Month YTD gives me total for entire month of November. I have tried the following so far
PMYTD = totalmtd(sum(SALES_VOUCHERS[SaleValue]),dateadd(DATESMTD(DatesTable[Date]),-1,month))
and
PMYTD = CALCULATE(sum(SALES_VOUCHERS[SaleValue]),
DATESBETWEEN(DatesTable[Date],
FIRSTDATE(PREVIOUSMONTH(DatesTable[Date])),
LASTDATE(DATEADD(DatesTable[Date],-1,MONTH))))
Both return the same answer which is total for the entire previous month .
If I simply hardcode the start and end date in datesbetween version above, then I do get the desired result. But that is not the solution.
I have linked the fact table (Sales_VOUCHERS) to a DatesTable and as of now there are no other visuals on the report page.
Kindly assist what I am missing out on and how I can get Previous Month year to date total
If you're aggregating at the month level (i.e. you're looking at December 2016 vs. November 2016), then the measure you have above will show you the entire month of December compared to the entire month of November (and since December is a partial month and November isn't, it causes the mismatch you see).
If you filter to the current date (e.g. 7th Dec), then both your MTD and Prior Month MTD measures will only show you through the 7th of their corresponding months.
Assuming you don't want to filter to the day level (not unreasonable), you could enhance your formula to filter out future dates. For example:
PMYTD = totalmtd(
sum(SALES_VOUCHERS[SaleValue]),
dateadd(
FILTER(
DATESMTD(DatesTable[Date]),
DatesTable[Date]<TODAY()
),
-1,
month
)
)
This says, if the date is after today, don't pass it into the TOTALMTD calculation (so it will only calculate the first 7 days of the month, for example, if today is Dec 8th - even if you're looking at full months on your report).
Side note: you can also write your previous month measure to re-use your MTD measure rather than redefining it. In this way, if you ever change the MTD calculation, the previous MTD calculation automatically updates.
PMYTD = CALCULATE(
[CurrentMTD],
DATEADD(
FILTER(
DatesTable[Date],
DatesTable[Date]<TODAY()
),
-1,
MONTH
)
)
Useful Resources:
https://www.powerpivotpro.com/2016/01/year-to-date-in-previousprior-year/ (article that covers this problem and a variety of solutions)
https://community.powerbi.com/t5/Desktop/Compare-MTD-with-previous-period/td-p/24656 (forum discussion about the same problem)
http://community.powerbi.com/t5/Desktop/Time-Intelligence-TOTALMTD-vs-DATESMTD-vs-DATEADD/td-p/10088 (forum discussion about DATESMTD vs TOTALMTD)