Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
AdisanonW
Frequent Visitor

How to add another Calculation for only fourth Quarter in this year

I have 2 date tables,
1 for filtering and 2 for chart displaying as per below.

AdisanonW_1-1660215423197.png

 

and as you can see the blank space in 2022 Q4, I need to calculate separately for only Q4. (forecast figure)

 

Below are the measures I have tried, but I struck on combining the values (18.1) with the main measure. (Net sales)

AdisanonW_2-1660215563165.png

 

The conditional for calculating Q4 is: Selected month of [Actual&Forecast] - (Q1 + Q2 + Q3)

 

Here is my DAX formula for Net sales (Main measure):

Net sales = 
var var_EndOfYear = ENDOFYEAR(dDate[Date])
var LYtoTY = DATESINPERIOD(dDate_M[PeriodID],var_EndOfYear,-2,YEAR)
Var Estimation = [SelectedEstimation]
var ActualTY = 
CALCULATE(
    [ActualTY], 
    REMOVEFILTERS(dDate),
    KEEPFILTERS(LYtoTY),
    USERELATIONSHIP(dDate[Date],dDate_M[PeriodID]),
         FILTER(dDate_m,dDate_m[Month] <= [selectedmonth] && dDate_m[Year] IN {[SelectedYear]})
         )

var ActualLY = 
CALCULATE(
    REMOVEFILTERS(dDate),
    KEEPFILTERS(LYtoTY),
    USERELATIONSHIP(dDate[Date],dDate_M[PeriodID]),
         FILTER(dDate_m,dDate_m[Year] IN {[SelectedYear] -1})
         )

var ForecastTY = 
CALCULATE(
    [ForecastTY],
    REMOVEFILTERS(dDate),
    KEEPFILTERS(LYtoTY),
    USERELATIONSHIP(dDate[Date],dDate_M[PeriodID]),
         FILTER(dDate_m,dDate_m[Month] > [SelectedMonth] && dDate_m[Year] IN { [SelectedYear]} && dDate_M[Quarter] <> 4)
         )

var sumActual = ActualTY + ActualLY + ForecastTY
return sumActual + "I have created another measure to combine here, but failed :("

 

And here is Q4 DAX formula:

Net sales Q4 = 
var Estimation = [SelectedEstimation]
var Q123 =
        CALCULATE(
    [Actual],
    FILTER(all(ddate),dDate[Month] <= SELECTEDVALUE(dDate[Month]) && dDate[Year] = SELECTEDVALUE(dDate[Year]) && dDate[Quarter No.] <> 4)
    )
         + 
    CALCULATE(
    [Forecast],
    FILTER(all(ddate),dDate[Month] > SELECTEDVALUE(dDate[Month]) && dDate[Year] = SELECTEDVALUE(dDate[Year])  && dDate[Quarter No.] <> 4)
    )

var FY = 
    CALCULATE(
    [FYActual],
    FILTER(all(ddate),dDate[Month] < SELECTEDVALUE(dDate[Month]) && dDate[Year] = SELECTEDVALUE(dDate[Year]))
    )
+
    CALCULATE(
    [FYForecast],
    FILTER(all(ddate),dDate[Month] >= SELECTEDVALUE(dDate[Month]) && dDate[Year] = SELECTEDVALUE(dDate[Year]))
    )

var BarQ4 = FY - Q123

    return BarQ4

 

Some suggestions?

Thanks 🙂

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @AdisanonW ,

I created some data:

vyangliumsft_0-1660716481952.png

Here are the steps you can follow:

1. Create measure.

Net sales =
1
Net sales Q4 = 2
Flag1 =
SWITCH(
TRUE(),
MAX('Table'[Year])=2022&&MAX('Table'[QTR])="Q4",[Net sales Q4],
HASONEVALUE('Table'[Year])&&HASONEVALUE('Table'[QTR]),[Net sales])
Flag2 =
var _table=
SUMMARIZE('Table','Table'[QTR],"value",[Flag1])
return
IF(
HASONEVALUE('Table'[QTR]),[Flag1],SUMX(_table,[value]))
all =
var _table=
SUMMARIZE('Table','Table'[Year],"value",[Flag2])
return
IF(
HASONEVALUE('Table'[Year]),[Flag2],SUMX(_table,[value]))

2. Result:

vyangliumsft_1-1660716481954.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi  @AdisanonW ,

I created some data:

vyangliumsft_0-1660716481952.png

Here are the steps you can follow:

1. Create measure.

Net sales =
1
Net sales Q4 = 2
Flag1 =
SWITCH(
TRUE(),
MAX('Table'[Year])=2022&&MAX('Table'[QTR])="Q4",[Net sales Q4],
HASONEVALUE('Table'[Year])&&HASONEVALUE('Table'[QTR]),[Net sales])
Flag2 =
var _table=
SUMMARIZE('Table','Table'[QTR],"value",[Flag1])
return
IF(
HASONEVALUE('Table'[QTR]),[Flag1],SUMX(_table,[value]))
all =
var _table=
SUMMARIZE('Table','Table'[Year],"value",[Flag2])
return
IF(
HASONEVALUE('Table'[Year]),[Flag2],SUMX(_table,[value]))

2. Result:

vyangliumsft_1-1660716481954.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

Wow! it works. Thank you so much 😄 @Anonymous 

AdisanonW
Frequent Visitor

My bad and thanks for your reply and suggestions.

 

Here is the expected result in Q4 2022 (referring to the screenshot I attached) :

YearQuarterNet sales

2021

Q115.0
2021Q218.2
2021Q318.6
2021Q426.9
2022Q123.9
2022Q224.2
2022Q322.2
2022Q418.1

 

And here is the sample data (fact table) :

 

CurrencyValueReportElementDataLevelOrganisationElementNameDateKey
EUR2051.42AActualT01-Jul-22
EUR-39.56BActualE01-Jun-22
EUR-221727.6CActualE01-Jul-22
EUR-5893821.02DActualE01-Jul-22
EUR676001.66EActualE01-Jul-22
EUR981124.04FActualT01-Jul-22
EUR3029083GEstimationT01-Dec-22

I don't think your sample data matches your expected output. Please verify, and also provide the forecast table.

I understand your point now.

Let me give you more context via this link (Excel), it is included the issue explanation and covered of sample data.

 

Thank you so much 🙂

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. I can only help you with meaningful sample data.
Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. Screenshots of your source data are not useful.
Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.