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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
AFra
Helper III
Helper III

Create new measure to compare values from two dates

Hi all, 

 

I have a table such as : 

 

Reporting dateID ProjectStatus # housesRP date
31-12-20VoltMS_Prep2407-07-24
31-12-20MiroiMS_AvProj13725-06-23
31-12-20PAS IIChantier10024-03-25
31-12-20NavezEn attente/bloqué6412-12-22
30-06-21VoltMS_Prep1807-07-24
30-06-21MiroiMS_AvProj13730-08-23
30-06-21PAS IIChantier10020-12-25
30-06-21NavezChantier7512-12-22
30-06-21LuttrMS_Prep10010-05-25

 

I would like to create several measures would allow me to compare data from the latest date (here 30-06-2021, but il will change over the time) to the previous one (here 31-12-2020). I need to display : 

- List of new projects (in the example : Luttr)

- List of projects that changed status (here : Navez)

- List of projects that changed # houses (here : Volt & Navez)

- List of projects that changed RP date (here : Miroi & PAS II)

 

I guess I need to use an if statement but I can't figure how to specify "compare each project based on the date. Take in account only the latest date & the previous one". 

 

thanks in advance for your help! 

Ana 

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @AFra 

 

This took me some time, but I got the results.
Create the following measures:
the Date:

_LastDate =
VAR _top1 =
    TOPN ( 1, ALL ( 'Table' ), [Reporting date], DESC )
RETURN
    MAXX ( _top1, [Reporting date] )
_previousDate =
VAR _t =
    FILTER ( ALL ( 'Table' ), 'Table'[Reporting date] < [_LastDate] )
VAR _preProject =
    TOPN ( 1, _t, [Reporting date], DESC )
VAR _preDate =
    SUMMARIZE ( _preProject, [Reporting date] )
RETURN
    MAXX ( _preDate, [Reporting date] )
// MAXX(FILTER(ALL('Table'),'Table'[Reporting date]<MAX('Table'[Reporting date])),[Reporting date])

 NewProject:

_NewProject =
VAR _preProject =
    SUMMARIZE (
        FILTER ( ALL ( 'Table' ), 'Table'[Reporting date] = [_previousDate] ),
        'Table'[ID Project]
    )
VAR _if =
    IF (
        MAX ( 'Table'[Reporting date] ) = [_LastDate],
        IF ( MAX ( 'Table'[ID Project] ) IN _preProject, BLANK (), 1 )
    )
RETURN
    _if

 House, RP date, Status:  
just change the distinctount field

_ChangeStatus =
VAR _count =
    SUMMARIZE (
        FILTER ( ALL ( 'Table' ), 'Table'[Reporting date] >= [_previousDate] ),
        [ID Project],
        "Count", DISTINCTCOUNT ( 'Table'[Status ] )
    )
VAR _Change =
    FILTER ( _count, [Count] > 1 )
VAR _Project =
    SUMMARIZE ( _Change, [ID Project] )
VAR _if =
    IF (
        MAX ( 'Table'[Reporting date] ) = [_LastDate],
        IF ( MAX ( 'Table'[ID Project] ) IN _Project, 1, BLANK () )
    )
RETURN
    _if

 Result:

vangzhengmsft_0-1625636293115.png

 

Please refer to the attachment below for details

 

 

Hope this helps.

 

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

4 REPLIES 4
v-angzheng-msft
Community Support
Community Support

Hi, @AFra 

 

This took me some time, but I got the results.
Create the following measures:
the Date:

_LastDate =
VAR _top1 =
    TOPN ( 1, ALL ( 'Table' ), [Reporting date], DESC )
RETURN
    MAXX ( _top1, [Reporting date] )
_previousDate =
VAR _t =
    FILTER ( ALL ( 'Table' ), 'Table'[Reporting date] < [_LastDate] )
VAR _preProject =
    TOPN ( 1, _t, [Reporting date], DESC )
VAR _preDate =
    SUMMARIZE ( _preProject, [Reporting date] )
RETURN
    MAXX ( _preDate, [Reporting date] )
// MAXX(FILTER(ALL('Table'),'Table'[Reporting date]<MAX('Table'[Reporting date])),[Reporting date])

 NewProject:

_NewProject =
VAR _preProject =
    SUMMARIZE (
        FILTER ( ALL ( 'Table' ), 'Table'[Reporting date] = [_previousDate] ),
        'Table'[ID Project]
    )
VAR _if =
    IF (
        MAX ( 'Table'[Reporting date] ) = [_LastDate],
        IF ( MAX ( 'Table'[ID Project] ) IN _preProject, BLANK (), 1 )
    )
RETURN
    _if

 House, RP date, Status:  
just change the distinctount field

_ChangeStatus =
VAR _count =
    SUMMARIZE (
        FILTER ( ALL ( 'Table' ), 'Table'[Reporting date] >= [_previousDate] ),
        [ID Project],
        "Count", DISTINCTCOUNT ( 'Table'[Status ] )
    )
VAR _Change =
    FILTER ( _count, [Count] > 1 )
VAR _Project =
    SUMMARIZE ( _Change, [ID Project] )
VAR _if =
    IF (
        MAX ( 'Table'[Reporting date] ) = [_LastDate],
        IF ( MAX ( 'Table'[ID Project] ) IN _Project, 1, BLANK () )
    )
RETURN
    _if

 Result:

vangzhengmsft_0-1625636293115.png

 

Please refer to the attachment below for details

 

 

Hope this helps.

 

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

thank you! it works nicely!!!

AFra
Helper III
Helper III

Hello @amitchandak

thank you for your suggestion, but it doesnt seem to work : it does not retrieve the right lists. 

Here's the full data if you - or anyone else - are in the mood for help : ) link to data 

amitchandak
Super User
Super User

@AFra , Create measures like

 

project Not having same status =
var _max = maxx(allselected(Table),Table[RP date])
var _max = minx(filter(allselected(Table),Table[RP date] <_max),Table[RP date])

var _maxs = calculate(Max(Table[Status]), filter(Table, Table[RP date] = _max)) //use allselected(Table) , if needed
var _mins =calculate(Max(Table[Status]), filter(Table, Table[RP date] = _max)) //use allselected(Table) , if needed
return
countx(values(Table[Project]), if(_maxs<> _minx ,[Project], blank()))


New Project =
var _max = maxx(allselected(Table),Table[RP date])
var _max = minx(filter(allselected(Table),Table[RP date] <_max),Table[RP date])

var _maxs = calculate(count(Table[Status]), filter(Table, Table[RP date] = _max))//use allselected(Table) , if needed
var _mins =calculate(count(Table[Status]), filter(Table, Table[RP date] = _max))//use allselected(Table) , if needed
return
countx(values(Table[Project]), if(isblank(_mins) && not(isblank(_maxs)) ,[Project], blank()))

 

The last two need to have the same approach like formula one

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.