Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Vinni2000
Contributor III
Contributor III

Compare this year data vs last year data

 I have invoice date '20200831' format in purchase order data so now i want to compare thise year purchase amount vs last year purchase amount by months using bar chart .

5 Replies
Loriguzman
Contributor II
Contributor II

Hello,

To compare this year's purchase amount versus last year's purchase amount by months using a bar chart, you will need the purchase data for both years. If you have the invoice dates in the format 'YYYYMMDD,' you can extract the year and month from the invoice dates to calculate the purchase amount for each month.

Here's a step-by-step guide to accomplish this:

Retrieve the purchase data for both years, including the invoice date and purchase amount. Ensure that the data includes the invoice dates in the 'YYYYMMDD' format.

Convert the invoice dates into a format that can be easily manipulated. You can use Python or any other programming language of your choice to accomplish this.

Extract the year and month from each invoice date. If the invoice date is in the format 'YYYYMMDD,' you can extract the year by taking the substring from index 0 to 4, and the month by taking the substring from index 4 to 6.

Calculate the purchase amount for each month by summing the purchase amounts for invoices in the same month.  McDVOICE

Separate the purchase amounts for each year (current year and last year).

Create a bar chart using a visualization library like Matplotlib or Plotly. The x-axis should represent the months, and the y-axis should represent the purchase amounts.

Plot the purchase amounts for the current year and last year side by side for each month. You can use different colors or patterns to differentiate between the two years.

Add labels, titles, and legends to make the chart more informative and visually appealing.

By following these steps, you should be able to compare the purchase amounts for each month between this year and last year using a bar chart.

I hope the information helps you. Thanks! 

 

 

 

Vinni2000
Contributor III
Contributor III
Author

IMG_20230526_192937.jpg

 i want my bar chart like this like i want to compare last 12 months data with previous 12 months data 

 

Kushal_Chawda

@Vinni2000  First create Calendar using InvoiceDate which contains Year & Month calculated using Invoice Date. Then create Bar chart with two dimension, 'Group' Month and 'Bars' as Year. Use below expression

Sum({<Year = {">=$(=max(Year)-1)"}>}Amount)

 

Screenshot 2023-05-30 at 11.44.23.png

Vinni2000
Contributor III
Contributor III
Author

Yeah I did the same and created month and year field from invoice create date using month() and year() then used same measures but i don't want that i want to compare this last 12 months means 2022 june to 2023 May with previous last 12 months means 2021 june to 2022 May

Kushal_Chawda

@Vinni2000  Considering you have calendar on required date. Create a Flag like below in Calendar

Calendar:
LOAD *,monthname(Date) as MonthYear,
     if(Date>= monthstart(addmonths(Today(),-11)) and Date <=Today(),'Last12Months',
     if(Date>= monthstart(addmonths(Today(),-23)) and Date<= monthend(addmonths(Today(),-12)) ,'PreviousLast12Months')) as Flag;

Month:
Load Distinct Month ,MonthYear
Resident Calendar
where Flag='Last12Months';

month_sort:
Load Month, RowNo() as Sort_month
Resident Month
Order by MonthYear;

Drop Table Month;

 

Create a bar chart with Dimension Month and below expression

Last12Month: Sum({<Flag={"Last12Months"}>}Sales)
Expression label: =text(monthname(min({<Flag={"Last12Months"}>}Date)))&'-'&text(monthname(max({<Flag={"Last12Months"}>}Date)))

PreviousLast12Month: Sum({<Flag={"PreviousLast12Months"}>}Sales)
Expression label: =text(monthname(min({<Flag={"PreviousLast12Months"}>}Date)))&'-'&text(monthname(max({<Flag={"PreviousLast12Months"}>}Date)))

 

Sort your Month Dimension by Expression =Sort_month

 Screenshot 2023-05-30 at 15.27.19.png