Show balance by month - Power BI - powerbi

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] )
)
)

Related

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

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] ) )
)

PowerBI / DAX - REMOVEFILTERS not working as expected

We are using a date table based on a fiscal calendar. I need to determine if a particular year has 53 weeks or 52 weeks.
The page has a slicer with a date hierarchy that is used to select a year, quarter, month, or week. I would like the Measure to return the maximum number of weeks in a particular year regardless of what is selected.
The measure below works fine, it returns 53 which is the maximum number of weeks in any year regardless of the selection in the date hierarchy slicer.
PriorYearNumberOfWeeks = calculate(max(vwPBIDate[Week of Year]),REMOVEFILTERS(vwPBIDate))
However, when I try to add a filter condition to select the proper year it no longer works it returns the maximum week number of the period selected in the hierarchy. If I select January (a 5 week month) it returns 5 instead of 53 then number weeks in fiscal 2021.
PriorYearNumberOfWeeks = calculate(max(vwPBIDate[Week of Year]),REMOVEFILTERS(vwPBIDate),filter(vwPBIDate,vwPBIDate[Fiscal Year Number]=2021))
You're missing an ALL:
=
CALCULATE(
MAX( vwPBIDate[Week of Year] ),
REMOVEFILTERS( vwPBIDate ),
FILTER(
ALL( vwPBIDate ),
vwPBIDate[Fiscal Year Number] = 2021
)
)
which is equivalent to:
=
CALCULATE(
MAX( vwPBIDate[Week of Year] ),
REMOVEFILTERS( vwPBIDate ),
vwPBIDate[Fiscal Year Number] = 2021
)

Calculate cumulative sum from beginning of year to filter selection

I have two tables
Calendar - Contains columns for year, quarter, YearQuarter
Sales - contains columns for Entity sold, sale price, date of sale, quarter of sale, year of sale.
I have a filter in my dashboard for Year and Quarter. I would like to create a measure that calculates the cumulative sum of sales from the beginning of the selected year to the selected quarter.
e.g. if Year = 2020, and Quarter = Q3, the measure should calculate the sum of sales from the beginning of 2020 until the end of Q3 2020.
If you had a well-formed date table, you could use time-intelligence functions DATESYTD or TOTALYTD as explained in The hidden secrets of TOTALYTD.
However, your calendar table doesn't qualify, so you need to do things a bit more manually.
Sales YTD =
VAR SelQtr = SELECTEDVALUE ( Calendar[Quarter] )
RETURN
CALCULATE (
[Sales],
ALLEXCEPT ( Calendar, Calendar[Year] ),
Calendar[Quarter] <= SelQtr
)
This removes any calendar filtering except for the year and filters for quarters up to the selected quarter.

POWER BI - Create a measure to compare Forecast vs Sales

Create a measure to compare forecast vs sales in power BI.
The logic is that at the beginning of Jan. 2018 it is forecasted the sales for the whole year and the amount of pcs sold in Jan. 2018 is only known in Feb. 2018 (next month's file). As an example, we are in Nov. 2018 and it is known how many pcs were sold in the previous months. I want to create a table to compare forecast vs sales.
My dataset looks like the figure below. It is marked in red the historical data.
An example of a power BI matrix that I am trying to create by dividing forecast by sales
It looks like you need to normalize your data source. This may look something like:
Now you can create some measures. Create a Forecast Qty measure:
Forecast Qty:=CALCULATE (
SUM ( SourceTable[Qty] ),
SourceTable[Type] = "Forecast"
)
A Sold Qty measure:
Sold Qty:=CALCULATE (
SUM ( SourceTable[Qty] ),
SourceTable[Type] = "Sold"
)
And a Sales % Forecast Measure:
Sales % Forecast:=DIVIDE (
[Sold Qty],
[Forecast Qty],
BLANK()
)
Now you can lay out your visualisation as you choose. For example:

Power BI DAX Calculation based on month selected in slicer

I need several measures in my report. The measure I want to start with is count of distinct ID four months before the month I selected on (e.g if I select on Aug 2018, the calculation would be all distinct ID before 30/04/2018). The reason I'm doing this is later on I also want to use this same slicer to work on count of ID within the four month period based on the selection.
Here is my DAX Calculation with comments:
Count four months ago =
// Find the end date of the month
VAR end_of_last_quarter =
FORMAT ( EOMONTH ( MAX ( 'Calendar'[Date] ), -4 ), "dd/mm/yyyy" )
RETURN
// Count distinct ID on or before that date
CALCULATE (
DISTINCTCOUNT ( 'Report Data'[Id] ),
FORMAT ( 'Report Data'[REPORT DATE], "d/mm/yyyy" )
<= FORMAT ( end_of_last_quarter, "d/mm/yyyy" )
)
& " Reports before "
& end_of_last_quarter
However after checking this calculation, it seems it only gives me the number of counts in the month I selected:
The screenshot tells me there are 12 report in Apr 2018, rather than the right number before 31/12/2017.
Thanks in advance for any ideas