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

How to Count only distinct years?

Hello,

I have a table as shown below:

NoCategoryDescriptionCustomerIndustryDurationValueLocationStart DateEnd DateContact
1RailingsAABCDSports24500000Australia3/25/20103/25/2012Z
2RailingsBEFGHOil3720000Indonesia6/12/20126/12/2015Y
3RailingsCIJKLMetals37250000Cambodia6/12/20126/12/2015X
4RailingsDMNOPSteel37450000Brunei6/12/20126/12/2015D

Now I want to define a measure called 'Experience' that counts the number of distinct years that the vendor above has provided the services in. For the example above, we can see that the vendor has provided these 4 services in the years: 2010,2011,2012,2013,2014,2015, so the value of 'Experience' will be 6. I am also doing this in the script part for your information. I have tried taking the sum of Year difference between the dates but the problem with this is it sums up even the non-distinct years and gives an inflated value. Please help me out with the logic for this. Thanks in advance!

stalwar1kaushik.solankitresesco

13 Replies
sunny_talwar

Check this

T1:

LOAD No.,

    [Equipment Category],

    Description,

    [Name of Client],

    Industry,

    [Duration (No of months)],

    Value,

    [Location of Services],

    [Start Date],

    [End Date],

    [Client’s Contact Person / Person-in-Charge],

    Year([Start Date]) as StartYear,

    Year([End Date]) as EndYear

FROM

[Book1.xlsx]

(ooxml, embedded labels, table is Sheet1);


Dates:

LOAD DISTINCT StartYear,

EndYear,

StartYear + IterNo() - 1 as Year

Resident T1

While StartYear + IterNo() - 1 <= EndYear;

wade12
Partner - Creator II
Partner - Creator II

T1:

LOAD Vendor,

     No.,

     [Equipment Category],

     Description,

     [Name of Client],

     Industry,

     [Duration (No of months)],

     Value,

     [Location of Services],

     [Start Date],

     Year([Start Date])      as     Year,

     [End Date],

     [Client’s Contact Person / Person-in-Charge]

FROM

(ooxml, embedded labels, table is Sheet1);

sunny_talwar

But if you are doing this by Vendor, I would do it like this

T1:

LOAD Vendor,

    No.,

    [Equipment Category],

    Description,

    [Name of Client],

    Industry,

    [Duration (No of months)],

    Value,

    [Location of Services],

    [Start Date],

    [End Date],

    [Client’s Contact Person / Person-in-Charge],

    Year([Start Date]) as StartYear,

    Year([End Date]) as EndYear

FROM

[Book1.xlsx]

(ooxml, embedded labels, table is Sheet1);


Dates:

LOAD DISTINCT Vendor,

     StartYear + IterNo() - 1 as Year

Resident T1

While StartYear + IterNo() - 1 <= EndYear;

mrthomasshelby
Creator III
Creator III
Author

Works like a charm! Understood it now! Thanks again Sunny!