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

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

Reply
Anonymous
Not applicable

Request for DAX Help

Dear All, 

I request help to solve a scenario.  I have a input table, using that I need to create a output report (Refer tables below). I am having trouble in creating the dax formulas for columns Shares Count Current Year, Shares Count Previous Year. The Report date should be as on today (current date). 

 

Please suggest.

 

Input Table:

Companyshareid

ValidfromValidtoSharecount
s1015/23/2017 0:006/27/2018 0:005
s1022/17/2018 0:005/20/2018 0:0020
s1035/23/2017 0:006/27/2018 0:0010
s1045/20/2017 0:006/27/2018 0:0015
s1055/24/2017 0:001/30/2018 0:005
s1065/24/2016 0:005/24/2017 0:0016

 

Output Report:

Companyshareid 

Shares Count Current YearShares Count Previous YearDifference

 

Appreciate all the help!

 

Regards,

rnagalla25

1 ACCEPTED SOLUTION

Hi @Anonymous

 

I think I see what you are after.  Please try the following three calculated measures.  I have attached a simple PBIX file that contains the measures.

 

Shares Count Current Year = 
VAR myDate = TODAY()
RETURN 
    SUMX(
        FILTER(
            'Table1',
            'Table1'[Validfrom] <= myDate &&   
            'Table1'[Validto] >= myDate
        ),
       'Table1'[Sharecount]
       )
Shares Count Previous Year = 
VAR myDate = EDATE(TODAY(),-12)
RETURN 
     SUMX(
        FILTER(
            'Table1',
            'Table1'[Validfrom] <= myDate &&   
            'Table1'[Validto] >= myDate
        ),
       'Table1'[Sharecount]
       )
Difference = [Shares Count Current Year] - [Shares Count Previous Year]

image.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

4 REPLIES 4
Phil_Seamark
Microsoft Employee
Microsoft Employee

What are the criteria for counting if a row should be considered as this year?  Does it have to start in this year or just be active at any point during the year?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Below is the logic they have given in the storeprocedure

@Date = getdate()

@FromDate = DATEADD(Year, -1, @Date)

ISNULL(dbo.GetShares(c.CompanyID, @Date),0) AS Shares count current year
,ISNULL(dbo.GetShares(c.CompanyID, @FromDate),0) AS Shares count Previous Year

 

GetShares Function is having below logic 

 

CONVERT(datetime,CONVERT(char(10),@Date,101)) BETWEEN CONVERT(datetime,CONVERT(char(10),ValidFrom,101)) AND CONVERT(datetime,CONVERT(char(10),ValidTo,101)) 

 

 

 

 

Hi @Anonymous

 

I think I see what you are after.  Please try the following three calculated measures.  I have attached a simple PBIX file that contains the measures.

 

Shares Count Current Year = 
VAR myDate = TODAY()
RETURN 
    SUMX(
        FILTER(
            'Table1',
            'Table1'[Validfrom] <= myDate &&   
            'Table1'[Validto] >= myDate
        ),
       'Table1'[Sharecount]
       )
Shares Count Previous Year = 
VAR myDate = EDATE(TODAY(),-12)
RETURN 
     SUMX(
        FILTER(
            'Table1',
            'Table1'[Validfrom] <= myDate &&   
            'Table1'[Validto] >= myDate
        ),
       'Table1'[Sharecount]
       )
Difference = [Shares Count Current Year] - [Shares Count Previous Year]

image.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Hi Phil Seamark,

 

Appreciate all your help.

 

Regrads,

rnagalla 

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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