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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
inna_sysco
Helper II
Helper II

Calculate a value from one table "with the condition" from another table

Hi community!

I need your help in creating an appropriate DAX.

The task is - calculate the sum of Table[VALUE] for the current month, but for line, where "Chart section" = "Opening" calculate the sum of the previous month(but still display for the current month)

I assume that the algorithm should be like that:
1. Find the line in the "CONFIG" table, where "Chart section" = "Opening".
2. Select CODE for this line (CONFIG[Code])
3. Find the same code in "Table"[CODE]
4. Calculate sum of "Table[VALUE]" where Code = selected code from CONFIG[Code] and DAYTIME - previous month.
image.png

My .pbx file with model and some data is attached.
Could someone help me to solve this case?

Best wishes, Inna

1 ACCEPTED SOLUTION

Hi , @inna_sysco 

Try measures as below:

Pervious_value = 
VAR currentdate =
    SELECTEDVALUE ( 'TABLE'[DAYTIME] )
VAR previousdate =
    EDATE ( currentdate, -1 )
RETURN
    CALCULATE ( SUM ( 'TABLE'[VALUE] ), 'TABLE'[DAYTIME] = previousdate )
Result = 
IF (
    SELECTEDVALUE ( CONFIG[CHART_SECTION] ) = "Opening",
    [Pervious_value],
    SELECTEDVALUE ( 'TABLE'[VALUE] )
)

 

26.pngPlease check my sample file for more  details.

 

Best Regards,
Community Support Team _ Eason
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

5 REPLIES 5
rajulshah
Resident Rockstar
Resident Rockstar

Hello @inna_sysco ,

 

So what I understand is you want a single table with Current Month and Previous month numbers with the CHART_SECTION, right? Please let me know if my understanding is correct or not so that I can help you out.

Hi, @rajulshah !
Thanks for the answer!
Yes, it's correct)
I need one matrix with different months in columns and values from Config[CHART_SECTION] in rows.
At the intersection of a column and a row should be displayed the value for the current month ( in the column for January 2021, the value for January 2021)
But for the row where Config[CHART_SECTION] = "Opening balance" should be displayed the previous month value (for ex: for January 2021, should be displayed value for December 2020)

Hi , @inna_sysco 

Try measures as below:

Pervious_value = 
VAR currentdate =
    SELECTEDVALUE ( 'TABLE'[DAYTIME] )
VAR previousdate =
    EDATE ( currentdate, -1 )
RETURN
    CALCULATE ( SUM ( 'TABLE'[VALUE] ), 'TABLE'[DAYTIME] = previousdate )
Result = 
IF (
    SELECTEDVALUE ( CONFIG[CHART_SECTION] ) = "Opening",
    [Pervious_value],
    SELECTEDVALUE ( 'TABLE'[VALUE] )
)

 

26.pngPlease check my sample file for more  details.

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-easonf-msft , if possible,  I have one more little question for you.
I tried to implement your solution for some custom ranges of dates... 
When I use the column with the original date (TABLE[Daytime]) it shows correct values just in line for the "previous month" (Opening) , all other values are wrong.. and I'm not able to configure the period (it display all months that have data)
image.png
When I use the custom column (Table[Format Daytime]) - I'm able to change the period, but values for the line "Opening" - BLANK...
inna_sysco_0-1616417042767.png

 


How can I change measures to have all data on the same date axis?
My .pbx is attached.

Hi @v-easonf-msft , thank you so much for the help, your solution works perfectly!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors