How to change year end in power bi? - powerbi

I have a matrix with column 1 as YEARMONTH (202001, 202002, ....)
Column 2 is SALES.
In the matrix currently the value for Jan to Dec 2020 gets summed for year 2020.
I want to have year to have months only from April to March. Example 2019 is Apr 2019 to Mar 2020. 2020 is Apr 2020 to Mar 2021.
How can I implement this in power bi?

Try with below:
Fiscal year
1. Create a FiscalYearNumber column as
FiscalYearNumber=If( Month([Date]) >= 7 , Year([Date]),Year([Date]) -1 )
FiscalYearDisplay = ="FY"&Right(Format([FiscalYearNumber],"0#"),2)&"-"&Right(Format([FiscalYearNumber]+1,"0#"),2)
2) Create a column called FiscalMonth
FiscalMonth=(If( Month([Date]) >= 7 , Month([Date]) - 6,Month([Date]) + 6 )
3) Create Fisical Quater
FiscalQuarterNumber = ROUNDUP ([FiscalMonth]/3,0)
FiscalQuarterDisplay= "FQ" & format([FiscalQuarterNumber],"0")

Related

Filter only MAX month figures Power BI Desktop

I have a table of values for orders per month by region that looks like this:
Orders Table
Orders (YTD)
Month
Year
1
Jan
2021
4
Feb
2021
4
Mar
2021
5
Apr
2021
14
May
2021
16
Jun
2021
17
Jul
2021
19
Aug
2021
22
Sep
2021
24
Oct
2021
34
Nov
2021
35
Dec
2021
1
Jan
2022
3
Feb
2022
4
Mar
2022
Along with a table that orders the months in sequence as below, that will be modelled to order the months in the first table so that they appear in sequence in graphs.
Monthly Sequence Table
Month Sequence
Month
1
Jan
2
Feb
3
Mar
4
Apr
5
May
6
Jun
7
Jul
8
Aug
9
Sep
10
Oct
11
Nov
12
Dec
Upon closer inspection of my data, I have realised that the number of orders per month are not the raw figure per month, but a cumulative total for every order in the calendar year so far (new orders for month + orders for preceding month). Firstly, I want to calculate the correct sum of orders per year, which should actually just be the MAX month from the orders table. Of course in most years this will be December, but for the current year it needs to be the latest month. I wanted to use a measure to calculate the MAX 'Monthly Sequence Table'[Month Sequence] number from each table, by year. I thought maybe a filter function would be used but could not work out exactly how to do this in DAX.
Secondly, and similarly, I want to calculate the actual number of orders per each individual month using DAX. In this case, I want to take the Orders (YTD) total for that month/year combination and subtract it from its immediately preceding month. What would the formula look like for this?
Thanks in advance.

How do I calculate average from June 1 to June 30 annually and make it a dynamic function using DAX?

I have two tables in PowerBI, one modified date and one fact for customer scores. The relationship will be using the "Month Num" column. Score assessments take place every June, so I would like to be able to have the scores for 12 months (June 1 to June 30) averaged. Then I will just have a card comparing the Previous year score and Current year score. Is there a way to do this dynamically, so I do not have to change the year in the function every new year? I know using the AVERAGE function will be nested into the function somehow, but I am getting confused not using a calendar year and not seasoned enough to use Time Intelligence functions yet.
Customer Score Table
Month
Month Num
Year
Score
Customer #
June
6
2020
94.9
11111
July
7
2020
97
11111
months
continue
2020
100
June
6
2021
89
22222
July
7
2021
91
22222
months
continue
2021
100
June
6
2022
93
33333
July
7
2022
94
33333
Date Table
Month
Month Num
Month Initial
january
1
J
feb
2
F
march
3
M
other
months
continued

How can I create a dynamic measure or column for an array in PowerBI?

Excel Example
I am attempting to recreate a similar chart in PowerBI as I did in excel seen below:
Here I have revenue per day. The chart shows the percent of days where revenue exceeds a fixed amount (100, 200, etc).
In PowerBI I know how to recreate the table that the chart is based on by defining a column, but it's not dynamic. I can't apply filters to change the column values.
I know I can apply filters to measures but when I try to replicate the formula as a measure I get an error, which I assume is due to the formula trying to return an array of values.
Here is my formula for the fixed column version:
table2 column = countx(
filter(
DayRevenueTable,
[Revenue]>Table2[DayRevenueExceeding])
,[Day])
/Total
Assuming your table looks like this:
Date
Revenue
04 January 2022
102
11 January 2022
162
17 January 2022
180
02 January 2022
185
12 January 2022
203
05 January 2022
278
01 January 2022
353
16 January 2022
449
14 January 2022
500
06 January 2022
515
08 January 2022
582
10 January 2022
600
03 January 2022
618
09 January 2022
626
13 January 2022
626
15 January 2022
706
18 January 2022
765
07 January 2022
895
You need to first create a table with your fixed values. Basically is the same concept as creating a parameter.
Using that table as a reference, you can create your calculation around Fixed Values[Value].
DAX: Fixed Values
Fixed Values = GENERATESERIES(100,1000,100)
DAX: Days When Revenue Exceeds Amount
Days When Revenue Exceeds Amount =
VAR CurrentFixedValue =
SELECTEDVALUE ( 'Fixed Values'[Value] )
VAR CountValues =
CALCULATE (
COUNTROWS ( 'Table' ),
'Table'[Revenue] < ( CurrentFixedValue + 100 )
)
VAR AllValues =
CALCULATE ( COUNTROWS ( 'Table' ), ALLSELECTED ( 'Table' ) )
VAR Calc =
DIVIDE ( CountValues, AllValues )
RETURN
Calc
Output

Calculate Variance in PowerBI using dax query

I am trying to create a variance measure in PowerBI.
This is the data that I have,
Month Year MonthNo Value
Jan 2016 1 700
Feb 2016 2 800
March 2016 3 900
April 2016 4 750
.
.
Jan 2017 13 690
Feb 2017 14 730
And My variance for the Month Number 7 should be like,
`{Avg(values(4,5,6) - Value(7)} / Value(7)`
i.e (Average of last 3 months value - current month value) / Current month value
How to do this in Power BI? Thanks.
If it is okay for you to use a column, I believe you could add one with this code to get what you want:
Variance = (CALCULATE(AVERAGEX(Sheet1,Sheet1[Value]),FILTER(FILTER(Sheet1,Sheet1[MonthNo]<=EARLIER(Sheet1[MonthNo])-1),Sheet1[MonthNo]>=EARLIER(Sheet1[MonthNo])-3))-Sheet1[Value])/Sheet1[Value]
You'll need to replace all instances of Sheet1 with the name of your table.
It'll give you something like this:

SAS - deleting duplicates on multiple variables

I am trying to delete the observations in my data set that are the same across multiple variables.
For example
RID Admission Date End Date
1 Jan 1 2014 Jan 3 2014>
1 January 1 Jan 3 2014
1 March 2 2014 March 5 2014
2 July 1 2014 July 8 2014
2 July 1 2014 July 8 2014
2 August 9 2014 August 24 2014
I would want to keep all unique admissions for each RID, but delete any observations with the same RID and the same admission/end dates.
Thanks!
PROC SORT DATA=work.yourdatasetin OUT=work.datasetout NODUPLICATES ;
BY rid ;
RUN ;
Something like this might also work.
proc sql;
create table work.yourdatasetout as
select distinct
*
from
work.yourdatasetin;
quit;