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
Anonymous
Not applicable

Masure Sum based on string and date column

Hello,

 

i am facing an issue when i want to create a measure to sum values in one column when :

  • values in one of the strings column equal to "Published Indicator"
  • latest date in date column

Example dataset :

IdTime Period DateKeyfigurePublished
123456783/14/2020ManualOverwrite0
123456783/14/2020IncrementalValue0
123456783/14/2020PublishedIndicator0
123456783/14/2020ReviewFlag0
125764233/7/2020ManualOverwrite1
125764233/7/2020IncrementalValue0
125764233/7/2020PublishedIndicator1
125764233/7/2020ReviewFlag0
265346652/29/2020ManualOverwrite1
265346652/29/2020IncrementalValue0
265346652/29/2020PublishedIndicator1
265346652/29/2020ReviewFlag1

 

I calculated the latest available date in separate measure :

 

 

 

 

LastWeek = CALCULATE(MAX('Table1'[Time Period Date]),'Table1'[Date when data was loaded to database]="History")

 

 

 

 

And then i tried :

 

1) 

 

 

 

LWPublishedv1 = CALCULATE(SUM('Table1'[Published]),'Table1'[Key Figure]="Published Indicator" && 'Table1'[Time Period Date]=[LastWeek])

 

 

 

Resulting with error :The expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression.

2)

 

 

 

LWPublishedv2 = 
VAR LW=MAX('Table1'[Time Period Date].[Date])
VAR LwPub=CALCULATE(SUM('Table1'[Value]),FILTER('Table1','Table1'[Key Figure]="Published Indicator"&& 'Table1'[Time Period Date].[Date]=LW))
RETURN
    LwPub

 

 

 

Resulting with returned value being (Blank)

3)

 

 

 

LWPublishedv3 = 
VAR LW=MAX('Table1'[Time Period Date].[Date])
VAR LwPub=CALCULATE(SUM('Table1'[Value]),FILTER(FILTER('Table1','Table1'[Time Period Date]=LW),'Table1'[Key Figure]="Published Indicator"))
RETURN
    LwPub

 

 

 

Resulting with the returned value being (Blank)

 

Can you help me understand where i am making the mistake ? 

 

12 REPLIES 12
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please try this instead of your first formula:

LWPublishedv1 =
CALCULATE (
    SUM ( 'Table1'[Published] ),
    FILTER (
        'Table1',
        'Table1'[Key Figure] = "Published Indicator"
            && 'Table1'[Time Period Date] = [LastWeek]
    )
)

If you still have any issue, please share the expected result as a screenshot here.

Expect your reply!

 

Best Regards,

Giotto Zhi

 

Anonymous
Not applicable

Hello All,

 

thank you for replying. I tried the formula but unfortunatelly it seems that the date filter is not working properly. The measure is calculating for all of the dates.

 

In the link file from which screenshot was taken  :   https://easyupload.io/l12f1a 

 

image.png

 

 

Hi  @Anonymous ,

 

Try to create calendar table and relate it with the Time period then adjust your Last week for the calendar table.

 

Check the PBIX file attach and tell me if this is the expected result.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hello,

 

thank you for your answer. Unfortunatelly this is not what i need to achieve. 

 

In a nutshell, what i need is a measure that will sum "Published" column when KeyFigure column is "Published Indicator" for last week from History (Date when added to database = History), Time Period = MAX ). 

 

In the file you shared the measure is summing not only for the last week but also for past weeks:

Hi  @Anonymous ,

 

Try the following code:

 

LWPublishedv1 =
CALCULATE (
    SUM ( Table1[Published] );
    FILTER (
        'Table1';
        'Table1'[Key Figure] = "Published Indicator"
            && (
                CALCULATE ( MAX ( Table1[Time Period Date] ); ALL ( 'CAlendar'[Date] ) )
                    = MAX ( Table1[Time Period Date] )
            )
                = TRUE ()
            && 'Table1'[Date when data was loaded to database] = "History"
    )
)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hello Miguel,

 

Power Bi is flagging multiple errors due to semicolons

 

image.png

Hi @Anonymous ,

 

This is related with regional settings on the computer replace the semicolons by commas and it will work accept the code:

LWPublishedv1 =
CALCULATE (
    SUM ( Table1[Published] ),
    FILTER (
        'Table1',
        'Table1'[Key Figure] = "Published Indicator"
            && (
                CALCULATE ( MAX ( Table1[Time Period Date] ), ALL ( 'CAlendar'[Date] ) )
                    = MAX ( Table1[Time Period Date] )
            )
                = TRUE ()
            && 'Table1'[Date when data was loaded to database] = "History"
    )
)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hello,

 

thank you for supporting on the topic. Unfortunatelly the new formula is giving same result as previous one. The Key Figure criteria is properly working ( it is summing only when Key Figure ="Published Indicator") but the date criteria is not working :

 

 

image.png

 

File : https://easyupload.io/k0xo1j

Hi  @Anonymous ,

 

Try the following code:

Measure =
SUMX (
    FILTER (
        SUMMARIZE (
            Table1,
            Table1[Date when data was loaded to database],
            Table1[Key Figure],
            "@Published", SUM ( Table1[Published] )
        ),
        Table1[Date when data was loaded to database] = "History"
            && Table1[Key Figure] = "Published Indicator"
            && (
                CALCULATE ( MAX ( Table1[Time Period Date] ), ALLSELECTED ( 'CAlendar'[Date] ) )
                    = MAX ( Table1[Time Period Date] )
            )
    )
    [@Published]
)

 

 

Also be aware that measures are calcuated with context, having the calendar table connected with your main table by the Table[TimePeriod] and Calendar[Date], you need to start using the Date as part of your visualizations and not the Time Period otherwise the calculations will get incorrect.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hello,

 

measure again is giving an error. Not sure why it is so hard to filter by last date 😞

 

Error.jpg

 

 

Hi @Anonymous ,

 

My bad lacking a separator on the formula before the [@Published]

 

Measure =
SUMX (
    FILTER (
        SUMMARIZE (
            Table1,
            Table1[Date when data was loaded to database],
            Table1[Key Figure],
            "@Published", SUM ( Table1[Published] )
        ),
        Table1[Date when data was loaded to database] = "History"
            && Table1[Key Figure] = "Published Indicator"
            && (
                CALCULATE ( MAX ( Table1[Time Period Date] ), ALLSELECTED ( 'CAlendar'[Date] ) )
                    = MAX ( Table1[Time Period Date] )
            )
    ),
    [@Published]
)

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @Anonymous ,

 

Can you share a sample file? Although you have a good presentation of the model I have some doubts so I can help you.

 

You refer to a Table1'[Date when data was loaded to database] column I don't that in the mockup data you present.

 

Another question is what is the result you want to have in the case of this calculation you also place a value column but that is not on your data.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.